Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 225363
Collapse All | Expand All

(-)conffile/conffile.c (-1 / +1 lines)
Lines 136-142 Link Here
136
	char linebuf[LINE_LEN+1];
136
	char linebuf[LINE_LEN+1];
137
	char *line = linebuf;
137
	char *line = linebuf;
138
138
139
	cfile = fopen(fname, "r");
139
	cfile = fopen64(fname, "r");
140
	if (!cfile)
140
	if (!cfile)
141
		return -ERROPEN;
141
		return -ERROPEN;
142
142
(-)doc/mysql.table.ipaddr-as-string (-1 / +1 lines)
Lines 11-17 Link Here
11
# Table structure for table 'ulog'
11
# Table structure for table 'ulog'
12
#
12
#
13
CREATE TABLE ulog (
13
CREATE TABLE ulog (
14
  id int(10) unsigned DEFAULT '0' NOT NULL auto_increment,
14
  id int(10) unsigned NOT NULL auto_increment,
15
  raw_mac varchar(80),
15
  raw_mac varchar(80),
16
  oob_time_sec int(10) unsigned,
16
  oob_time_sec int(10) unsigned,
17
  oob_time_usec int(10) unsigned,
17
  oob_time_usec int(10) unsigned,
(-)doc/sqlite3.table (+3 lines)
Lines 2-7 Link Here
2
			raw_mac		VARCHAR(80),
2
			raw_mac		VARCHAR(80),
3
			oob_time_sec	INT UNSIGNED,
3
			oob_time_sec	INT UNSIGNED,
4
			oob_time_usec	INT UNSIGNED,
4
			oob_time_usec	INT UNSIGNED,
5
			oob_prefix	VARCHAR(32),
6
			oob_in		VARCHAR(32),
7
			oob_out		VARCHAR(32),
5
			ip_saddr	INT UNSIGNED,
8
			ip_saddr	INT UNSIGNED,
6
			ip_daddr	INT UNSIGNED,
9
			ip_daddr	INT UNSIGNED,
7
			ip_protocol	TINYINT UNSIGNED,
10
			ip_protocol	TINYINT UNSIGNED,
(-)extensions/printpkt.c (+1 lines)
Lines 267-272 Link Here
267
			  strerror(errno));
267
			  strerror(errno));
268
		exit(2);
268
		exit(2);
269
	}
269
	}
270
	hostname[sizeof(hostname)-1] = '\0';
270
271
271
	if (get_ids())
272
	if (get_ids())
272
		return 1;
273
		return 1;
(-)extensions/ulogd_BASE.c (-6 / +18 lines)
Lines 32-37 Link Here
32
32
33
#include <stdio.h>
33
#include <stdio.h>
34
#include <stdlib.h>
34
#include <stdlib.h>
35
#include <string.h>
35
#include <sys/socket.h>
36
#include <sys/socket.h>
36
#include <netinet/ip.h>
37
#include <netinet/ip.h>
37
#include <netinet/in.h>
38
#include <netinet/in.h>
Lines 62-73 Link Here
62
				ulog_packet_msg_t *pkt)
63
				ulog_packet_msg_t *pkt)
63
{
64
{
64
	unsigned char *p;
65
	unsigned char *p;
65
	int i;
66
	int i, tmp, len = 0;
66
	char *buf, *oldbuf = NULL;
67
	char *buf, *ptr = NULL;
67
	ulog_iret_t *ret = ip->result;
68
	ulog_iret_t *ret = ip->result;
69
	size_t siz;
68
70
69
	if (pkt->mac_len) {
71
	if (pkt->mac_len) {
70
		buf = (char *) malloc(3 * pkt->mac_len + 1);
72
		siz = 3 * pkt->mac_len + 1;
73
		buf = (char *) malloc(siz);
71
		if (!buf) {
74
		if (!buf) {
72
			ulogd_log(ULOGD_ERROR, "OOM!!!\n");
75
			ulogd_log(ULOGD_ERROR, "OOM!!!\n");
73
			return NULL;
76
			return NULL;
Lines 75-83 Link Here
75
		*buf = '\0';
78
		*buf = '\0';
76
79
77
		p = pkt->mac;
80
		p = pkt->mac;
78
		oldbuf = buf;
81
		ptr = buf;
79
		for (i = 0; i < pkt->mac_len; i++, p++)
82
		for (i = 0; i < pkt->mac_len; i++, p++) {
80
			sprintf(buf, "%s%02x%c", oldbuf, *p, i==pkt->mac_len-1 ? ' ':':');
83
			tmp = snprintf(ptr+len, siz-len, "%02x%s", 
84
					*p, i==pkt->mac_len-1 ? "":":");
85
			if (tmp < 0)
86
				break;
87
			if (tmp >= siz-len) {
88
				buf[siz] = '\0';
89
				break;
90
			}
91
			len += tmp;
92
		}
81
		ret[0].value.ptr = buf;
93
		ret[0].value.ptr = buf;
82
		ret[0].flags |= ULOGD_RETF_VALID;
94
		ret[0].flags |= ULOGD_RETF_VALID;
83
	}
95
	}
(-)extensions/ulogd_LOCAL.c (+1 lines)
Lines 93-98 Link Here
93
			  strerror(errno));
93
			  strerror(errno));
94
		exit(2);
94
		exit(2);
95
	}
95
	}
96
	hostname[sizeof(hostname)-1] = '\0';
96
	/* strip off everything after first '.' */
97
	/* strip off everything after first '.' */
97
	if ((tmp = strchr(hostname, '.')))
98
	if ((tmp = strchr(hostname, '.')))
98
		*tmp = '\0';
99
		*tmp = '\0';
(-)extensions/ulogd_LOGEMU.c (-4 / +7 lines)
Lines 79-93 Link Here
79
79
80
static void signal_handler_logemu(int signal)
80
static void signal_handler_logemu(int signal)
81
{
81
{
82
	FILE *old=of;
83
82
	switch (signal) {
84
	switch (signal) {
83
	case SIGHUP:
85
	case SIGHUP:
84
		ulogd_log(ULOGD_NOTICE, "syslogemu: reopening logfile\n");
86
		ulogd_log(ULOGD_NOTICE, "syslogemu: reopening logfile\n");
85
		fclose(of);
87
		of = fopen64(syslogf_ce.u.string, "a");
86
		of = fopen(syslogf_ce.u.string, "a");
87
		if (!of) {
88
		if (!of) {
88
			ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n",
89
			ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n",
89
				strerror(errno));
90
				strerror(errno));
90
			exit(2);
91
			of=old;
92
		} else {
93
			fclose(old);
91
		}
94
		}
92
		break;
95
		break;
93
	default:
96
	default:
Lines 103-109 Link Here
103
#ifdef DEBUG_LOGEMU
106
#ifdef DEBUG_LOGEMU
104
	of = stdout;
107
	of = stdout;
105
#else
108
#else
106
	of = fopen(syslogf_ce.u.string, "a");
109
	of = fopen64(syslogf_ce.u.string, "a");
107
	if (!of) {
110
	if (!of) {
108
		ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n", 
111
		ulogd_log(ULOGD_FATAL, "can't open syslogemu: %s\n", 
109
			strerror(errno));
112
			strerror(errno));
(-)extensions/ulogd_OPRINT.c (-5 / +10 lines)
Lines 72-78 Link Here
72
					HIPQUAD(ret->value.ui32));
72
					HIPQUAD(ret->value.ui32));
73
				break;
73
				break;
74
			case ULOGD_RET_NONE:
74
			case ULOGD_RET_NONE:
75
				fprintf(of, "<none>");
75
				fprintf(of, "<none>\n");
76
				break;
77
			default:
78
				fprintf(of, "\n");
76
				break;
79
				break;
77
		}
80
		}
78
	}
81
	}
Lines 88-103 Link Here
88
91
89
static void sighup_handler_print(int signal)
92
static void sighup_handler_print(int signal)
90
{
93
{
94
	FILE *old=of;
91
95
92
	switch (signal) {
96
	switch (signal) {
93
	case SIGHUP:
97
	case SIGHUP:
94
		ulogd_log(ULOGD_NOTICE, "PKTLOG: reopening logfile\n");
98
		ulogd_log(ULOGD_NOTICE, "PKTLOG: reopening logfile\n");
95
		fclose(of);
99
		of = fopen64(outf_ce.u.string, "a");
96
		of = fopen(outf_ce.u.string, "a");
97
		if (!of) {
100
		if (!of) {
98
			ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n",
101
			ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n",
99
				strerror(errno));
102
				strerror(errno));
100
			exit(2);
103
			of=old;
104
		} else {
105
			fclose(old);
101
		}
106
		}
102
		break;
107
		break;
103
	default:
108
	default:
Lines 112-118 Link Here
112
#else
117
#else
113
	config_parse_file("OPRINT", &outf_ce);
118
	config_parse_file("OPRINT", &outf_ce);
114
119
115
	of = fopen(outf_ce.u.string, "a");
120
	of = fopen64(outf_ce.u.string, "a");
116
	if (!of) {
121
	if (!of) {
117
		ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n", 
122
		ulogd_log(ULOGD_FATAL, "can't open PKTLOG: %s\n", 
118
			strerror(errno));
123
			strerror(errno));
(-)extensions/ulogd_PWSNIFF.c (-2 / +2 lines)
Lines 116-122 Link Here
116
			return NULL;
116
			return NULL;
117
		}
117
		}
118
		strncpy(ret[0].value.ptr, (char *)begp, len);
118
		strncpy(ret[0].value.ptr, (char *)begp, len);
119
		*((char *)ret[0].value.ptr + len + 1) = '\0';
119
		*((char *)ret[0].value.ptr + len) = '\0';
120
	}
120
	}
121
	if (pw_len) {
121
	if (pw_len) {
122
		ret[1].value.ptr = (char *) malloc(pw_len+1);
122
		ret[1].value.ptr = (char *) malloc(pw_len+1);
Lines 126-132 Link Here
126
			return NULL;
126
			return NULL;
127
		}
127
		}
128
		strncpy(ret[1].value.ptr, (char *)pw_begp, pw_len);
128
		strncpy(ret[1].value.ptr, (char *)pw_begp, pw_len);
129
		*((char *)ret[1].value.ptr + pw_len + 1) = '\0';
129
		*((char *)ret[1].value.ptr + pw_len) = '\0';
130
130
131
	}
131
	}
132
	return ret;
132
	return ret;
(-)libipulog/include/libipulog/libipulog.h (-1 / +1 lines)
Lines 12-18 Link Here
12
#include <asm/types.h>
12
#include <asm/types.h>
13
#include <linux/netlink.h>
13
#include <linux/netlink.h>
14
#include <net/if.h>
14
#include <net/if.h>
15
#include <linux/netfilter_ipv4/ipt_ULOG.h>
15
#include "linux/netfilter_ipv4/ipt_ULOG.h"
16
16
17
/* FIXME: glibc sucks */
17
/* FIXME: glibc sucks */
18
#ifndef MSG_TRUNC 
18
#ifndef MSG_TRUNC 
(-)libipulog/include/linux/netfilter_ipv4/ipt_ULOG.h (+62 lines)
Line 0 Link Here
1
/* Header file for IP tables userspace logging, Version 1.8
2
 *
3
 * (C) 2000-2002 by Harald Welte <laforge@gnumonks.org>
4
 * 
5
 * Distributed under the terms of GNU GPL */
6
#ifndef _IPT_ULOG_H
7
#define _IPT_ULOG_H
8
9
#ifndef NETLINK_NFLOG
10
#define NETLINK_NFLOG 	5
11
#endif
12
13
#define ULOG_DEFAULT_NLGROUP	1
14
#define ULOG_DEFAULT_QTHRESHOLD	1
15
16
#define ULOG_MAC_LEN	80
17
#define ULOG_PREFIX_LEN	32
18
19
#define ULOG_MAX_QLEN	50
20
/* Why 50? Well... there is a limit imposed by the slab cache 131000
21
 * bytes. So the multipart netlink-message has to be < 131000 bytes.
22
 * Assuming a standard ethernet-mtu of 1500, we could define this up
23
 * to 80... but even 50 seems to be big enough. */
24
25
/* private data structure for each rule with a ULOG target */
26
struct ipt_ulog_info {
27
	unsigned int nl_group;
28
#ifdef KERNEL_64_USERSPACE_32
29
	unsigned long long copy_range;
30
	unsigned long long qthreshold;
31
#else
32
	size_t copy_range;
33
	size_t qthreshold;
34
#endif
35
	char prefix[ULOG_PREFIX_LEN];
36
};
37
38
/* Format of the ULOG packets passed through netlink */
39
typedef struct ulog_packet_msg {
40
	unsigned long mark;
41
#ifdef KERNEL_64_USERSPACE_32
42
	long long timestamp_sec;
43
	long long timestamp_usec;
44
#else
45
	long timestamp_sec;
46
	long timestamp_usec;
47
#endif
48
	unsigned int hook;
49
	char indev_name[IFNAMSIZ];
50
	char outdev_name[IFNAMSIZ];
51
#ifdef KERNEL_64_USERSPACE_32
52
	unsigned long long data_len;
53
#else
54
	size_t data_len;
55
#endif
56
	char prefix[ULOG_PREFIX_LEN];
57
	unsigned char mac_len;
58
	unsigned char mac[ULOG_MAC_LEN];
59
	unsigned char payload[0];
60
} ulog_packet_msg_t;
61
62
#endif /*_IPT_ULOG_H*/
(-)Makefile.in (-3 / +2 lines)
Lines 54-69 Link Here
54
54
55
.PHONY: diff
55
.PHONY: diff
56
diff: $(RELEASE_DIR)/ulogd-$(ULOGD_VERSION).tar.bz2
56
diff: $(RELEASE_DIR)/ulogd-$(ULOGD_VERSION).tar.bz2
57
	@[ -d /tmp/diffdir ] || mkdir /tmp/diffdir
57
	@mkdir /tmp/diffdir
58
	@cd /tmp/diffdir && tar -x --bzip2 -f $(RELEASE_DIR)/ulogd-$(ULOGD_VERSION).tar.bz2
58
	@cd /tmp/diffdir && tar -x --bzip2 -f $(RELEASE_DIR)/ulogd-$(ULOGD_VERSION).tar.bz2
59
	@set -e; cd /tmp/diffdir; tar -x --bzip2 -f $(RELEASE_DIR)/ulogd-$(OLD_ULOGD_VERSION).tar.bz2; echo Creating patch-ulogd-$(OLD_ULOGD_VERSION)-$(ULOGD_VERSION).bz2; diff -urN ulogd-$(OLD_ULOGD_VERSION) ulogd-$(ULOGD_VERSION) | bzip2 -9 > $(RELEASE_DIR)/patch-ulogd-$(OLD_ULOGD_VERSION)-$(ULOGD_VERSION).bz2
59
	@set -e; cd /tmp/diffdir; tar -x --bzip2 -f $(RELEASE_DIR)/ulogd-$(OLD_ULOGD_VERSION).tar.bz2; echo Creating patch-ulogd-$(OLD_ULOGD_VERSION)-$(ULOGD_VERSION).bz2; diff -urN ulogd-$(OLD_ULOGD_VERSION) ulogd-$(ULOGD_VERSION) | bzip2 -9 > $(RELEASE_DIR)/patch-ulogd-$(OLD_ULOGD_VERSION)-$(ULOGD_VERSION).bz2
60
	@rm -rf /tmp/diffdir
61
60
62
recurse: 
61
recurse: 
63
	@for d in $(SUBDIRS); do if ! make -C $$d; then exit 1; fi; done
62
	@for d in $(SUBDIRS); do if ! make -C $$d; then exit 1; fi; done
64
63
65
ulogd: ulogd.c $(LIBIPULOG) include/ulogd/ulogd.h conffile/conffile.o $(LIBIPULOG)/libipulog.a ulogd.conf
64
ulogd: ulogd.c $(LIBIPULOG) include/ulogd/ulogd.h conffile/conffile.o $(LIBIPULOG)/libipulog.a ulogd.conf
66
	$(CC) $(CFLAGS) -rdynamic $< conffile/conffile.o $(LIBIPULOG)/libipulog.a -o $@ $(LIBS)
65
	$(CC) $(CFLAGS) $(LDFLAGS) -rdynamic $< conffile/conffile.o $(LIBIPULOG)/libipulog.a -o $@ $(LIBS)
67
66
68
edit = sed -e 's,@libdir\@,$(ULOGD_LIB_PATH),g'
67
edit = sed -e 's,@libdir\@,$(ULOGD_LIB_PATH),g'
69
68
(-)mysql/ulogd_MYSQL.c (-39 / +110 lines)
Lines 43-48 Link Here
43
#include <ulogd/ulogd.h>
43
#include <ulogd/ulogd.h>
44
#include <ulogd/conffile.h>
44
#include <ulogd/conffile.h>
45
#include <mysql/mysql.h>
45
#include <mysql/mysql.h>
46
#include <inttypes.h>
46
47
47
#ifdef DEBUG_MYSQL
48
#ifdef DEBUG_MYSQL
48
#define DEBUGP(x, args...)	fprintf(stderr, x, ## args)
49
#define DEBUGP(x, args...)	fprintf(stderr, x, ## args)
Lines 53-58 Link Here
53
struct _field {
54
struct _field {
54
	char name[ULOGD_MAX_KEYLEN];
55
	char name[ULOGD_MAX_KEYLEN];
55
	unsigned int id;
56
	unsigned int id;
57
	unsigned int str;
56
	struct _field *next;
58
	struct _field *next;
57
};
59
};
58
60
Lines 68-79 Link Here
68
/* buffer for our insert statement */
70
/* buffer for our insert statement */
69
static char *stmt;
71
static char *stmt;
70
72
73
/* size of our insert statement buffer */
74
static size_t stmt_siz;
75
71
/* pointer to the beginning of the "VALUES" part */
76
/* pointer to the beginning of the "VALUES" part */
72
static char *stmt_val;
77
static char *stmt_val;
73
78
74
/* pointer to current inser position in statement */
79
/* pointer to current inser position in statement */
75
static char *stmt_ins;
80
static char *stmt_ins;
76
81
82
#define STMT_ADD(pos, fmt...) \
83
	do { 								      \
84
		if ((pos) >= stmt && stmt_siz > (pos) - stmt)            \
85
			snprintf((pos), stmt_siz-((pos)-stmt), ##fmt); \
86
	} while(0)
87
77
/* Attempt to reconnect if connection is lost */
88
/* Attempt to reconnect if connection is lost */
78
time_t reconnect = 0;
89
time_t reconnect = 0;
79
#define TIME_ERR		((time_t)-1)	/* Be paranoid */
90
#define TIME_ERR		((time_t)-1)	/* Be paranoid */
Lines 132-137 Link Here
132
};
143
};
133
144
134
static int _mysql_init_db(ulog_iret_t *result);
145
static int _mysql_init_db(ulog_iret_t *result);
146
static void _mysql_fini(void);
135
147
136
/* our main output function, called by ulogd */
148
/* our main output function, called by ulogd */
137
static int mysql_output(ulog_iret_t *result)
149
static int mysql_output(ulog_iret_t *result)
Lines 142-147 Link Here
142
	char *tmpstr;		/* need this for --log-ip-as-string */
154
	char *tmpstr;		/* need this for --log-ip-as-string */
143
	struct in_addr addr;
155
	struct in_addr addr;
144
#endif
156
#endif
157
	size_t esclen;
158
159
	if (stmt_val == NULL) {
160
		_mysql_fini();
161
		return _mysql_init_db(result);
162
	}
145
163
146
	stmt_ins = stmt_val;
164
	stmt_ins = stmt_val;
147
165
Lines 155-214 Link Here
155
			
173
			
156
		if (!res || !IS_VALID((*res))) {
174
		if (!res || !IS_VALID((*res))) {
157
			/* no result, we have to fake something */
175
			/* no result, we have to fake something */
158
			sprintf(stmt_ins, "NULL,");
176
			STMT_ADD(stmt_ins,"NULL,");
159
			stmt_ins = stmt + strlen(stmt);
177
			stmt_ins = stmt + strlen(stmt);
160
			continue;
178
			continue;
161
		}
179
		}
162
		
180
		
163
		switch (res->type) {
181
		switch (res->type) {
164
			case ULOGD_RET_INT8:
182
			case ULOGD_RET_INT8:
165
				sprintf(stmt_ins, "%d,", res->value.i8);
183
				STMT_ADD(stmt_ins,"%d,", res->value.i8);
166
				break;
184
				break;
167
			case ULOGD_RET_INT16:
185
			case ULOGD_RET_INT16:
168
				sprintf(stmt_ins, "%d,", res->value.i16);
186
				STMT_ADD(stmt_ins,"%d,", res->value.i16);
169
				break;
187
				break;
170
			case ULOGD_RET_INT32:
188
			case ULOGD_RET_INT32:
171
				sprintf(stmt_ins, "%d,", res->value.i32);
189
				STMT_ADD(stmt_ins,"%d,", res->value.i32);
172
				break;
190
				break;
173
			case ULOGD_RET_INT64:
191
			case ULOGD_RET_INT64:
174
				sprintf(stmt_ins, "%lld,", res->value.i64);
192
				STMT_ADD(stmt_ins,"%"PRId64",", res->value.i64);
175
				break;
193
				break;
176
			case ULOGD_RET_UINT8:
194
			case ULOGD_RET_UINT8:
177
				sprintf(stmt_ins, "%u,", res->value.ui8);
195
				STMT_ADD(stmt_ins,"%u,", res->value.ui8);
178
				break;
196
				break;
179
			case ULOGD_RET_UINT16:
197
			case ULOGD_RET_UINT16:
180
				sprintf(stmt_ins, "%u,", res->value.ui16);
198
				STMT_ADD(stmt_ins,"%u,", res->value.ui16);
181
				break;
199
				break;
182
			case ULOGD_RET_IPADDR:
200
			case ULOGD_RET_IPADDR:
183
#ifdef IP_AS_STRING
201
#ifdef IP_AS_STRING
184
				memset(&addr, 0, sizeof(addr));
202
				if (f->str) {
185
				addr.s_addr = ntohl(res->value.ui32);
203
					addr.s_addr = ntohl(res->value.ui32);
186
				*stmt_ins++ = '\'';
204
					tmpstr = inet_ntoa(addr);
187
				tmpstr = inet_ntoa(addr);
205
					esclen = (strlen(tmpstr)*2) + 4;
206
					if (stmt_siz <= (stmt_ins-stmt)+esclen){
207
						STMT_ADD(stmt_ins,"'',");
208
						break;
209
					}
210
211
					*stmt_ins++ = '\'';
188
#ifdef OLD_MYSQL
212
#ifdef OLD_MYSQL
189
				mysql_escape_string(stmt_ins, tmpstr,
213
					mysql_escape_string(stmt_ins,
190
						    strlen(tmpstr));
214
							    tmpstr,
215
							    strlen(tmpstr));
191
#else
216
#else
192
				mysql_real_escape_string(dbh, stmt_ins,
217
					mysql_real_escape_string(dbh, 
193
							 tmpstr,
218
								stmt_ins,
194
							 strlen(tmpstr));
219
								tmpstr,
220
								strlen(tmpstr));
195
#endif /* OLD_MYSQL */
221
#endif /* OLD_MYSQL */
196
                                stmt_ins = stmt + strlen(stmt);
222
	                                stmt_ins = stmt + strlen(stmt);
197
                                sprintf(stmt_ins, "',");
223
					STMT_ADD(stmt_ins, "',");
198
                                break;
224
					break;
225
				}
199
#endif /* IP_AS_STRING */
226
#endif /* IP_AS_STRING */
200
				/* EVIL: fallthrough when logging IP as
227
				/* EVIL: fallthrough when logging IP as
201
				 * u_int32_t */
228
				 * u_int32_t */
202
			case ULOGD_RET_UINT32:
229
			case ULOGD_RET_UINT32:
203
				sprintf(stmt_ins, "%u,", res->value.ui32);
230
				STMT_ADD(stmt_ins, "%u,", res->value.ui32);
204
				break;
231
				break;
205
			case ULOGD_RET_UINT64:
232
			case ULOGD_RET_UINT64:
206
				sprintf(stmt_ins, "%llu,", res->value.ui64);
233
				STMT_ADD(stmt_ins,"%"PRIu64",",res->value.ui64);
207
				break;
234
				break;
208
			case ULOGD_RET_BOOL:
235
			case ULOGD_RET_BOOL:
209
				sprintf(stmt_ins, "'%d',", res->value.b);
236
				STMT_ADD(stmt_ins, "'%d',", res->value.b);
210
				break;
237
				break;
211
			case ULOGD_RET_STRING:
238
			case ULOGD_RET_STRING:
239
				esclen = (strlen(res->value.ptr)*2) + 4;
240
				if (stmt_siz <= (stmt_ins-stmt) + esclen) {
241
					STMT_ADD(stmt_ins, "'',");
242
					break;
243
				}
212
				*stmt_ins++ = '\'';
244
				*stmt_ins++ = '\'';
213
#ifdef OLD_MYSQL
245
#ifdef OLD_MYSQL
214
				mysql_escape_string(stmt_ins, res->value.ptr,
246
				mysql_escape_string(stmt_ins, res->value.ptr,
Lines 218-225 Link Here
218
					res->value.ptr, strlen(res->value.ptr));
250
					res->value.ptr, strlen(res->value.ptr));
219
#endif
251
#endif
220
				stmt_ins = stmt + strlen(stmt);
252
				stmt_ins = stmt + strlen(stmt);
221
				sprintf(stmt_ins, "',");
253
				STMT_ADD(stmt_ins,"',");
222
			/* sprintf(stmt_ins, "'%s',", res->value.ptr); */
223
				break;
254
				break;
224
			case ULOGD_RET_RAW:
255
			case ULOGD_RET_RAW:
225
				ulogd_log(ULOGD_NOTICE,
256
				ulogd_log(ULOGD_NOTICE,
Lines 235-240 Link Here
235
		stmt_ins = stmt + strlen(stmt);
266
		stmt_ins = stmt + strlen(stmt);
236
	}
267
	}
237
	*(stmt_ins - 1) = ')';
268
	*(stmt_ins - 1) = ')';
269
	*stmt_ins = '\0';
270
238
	DEBUGP("stmt=#%s#\n", stmt);
271
	DEBUGP("stmt=#%s#\n", stmt);
239
272
240
	/* now we have created our statement, insert it */
273
	/* now we have created our statement, insert it */
Lines 242-247 Link Here
242
	if (mysql_real_query(dbh, stmt, strlen(stmt))) {
275
	if (mysql_real_query(dbh, stmt, strlen(stmt))) {
243
		ulogd_log(ULOGD_ERROR, "sql error during insert: %s\n",
276
		ulogd_log(ULOGD_ERROR, "sql error during insert: %s\n",
244
				mysql_error(dbh));
277
				mysql_error(dbh));
278
		_mysql_fini();
245
		return _mysql_init_db(result);
279
		return _mysql_init_db(result);
246
	}
280
	}
247
281
Lines 261-267 Link Here
261
static int mysql_createstmt(void)
295
static int mysql_createstmt(void)
262
{
296
{
263
	struct _field *f;
297
	struct _field *f;
264
	unsigned int size;
265
	char buf[ULOGD_MAX_KEYLEN];
298
	char buf[ULOGD_MAX_KEYLEN];
266
	char *underscore;
299
	char *underscore;
267
300
Lines 269-304 Link Here
269
		free(stmt);
302
		free(stmt);
270
303
271
	/* caclulate the size for the insert statement */
304
	/* caclulate the size for the insert statement */
272
	size = strlen(MYSQL_INSERTTEMPL) + strlen(table_ce.u.string);
305
	stmt_siz = strlen(MYSQL_INSERTTEMPL) + strlen(table_ce.u.string) + 1;
273
306
274
	for (f = fields; f; f = f->next) {
307
	for (f = fields; f; f = f->next) {
275
		/* we need space for the key and a comma, as well as
308
		/* we need space for the key and a comma, as well as
276
		 * enough space for the values */
309
		 * enough space for the values */
277
		size += strlen(f->name) + 1 + MYSQL_VALSIZE;
310
		stmt_siz += strlen(f->name) + 1 + MYSQL_VALSIZE;
278
	}	
311
	}	
279
312
280
	ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", size);
313
	ulogd_log(ULOGD_DEBUG, "allocating %zu bytes for statement\n",
314
				stmt_siz);
281
315
282
	stmt = (char *) malloc(size);
316
	stmt = (char *) malloc(stmt_siz);
283
317
284
	if (!stmt) {
318
	if (!stmt) {
319
		stmt_val = NULL;
320
		stmt_siz = 0;
285
		ulogd_log(ULOGD_ERROR, "OOM!\n");
321
		ulogd_log(ULOGD_ERROR, "OOM!\n");
286
		return -1;
322
		return -1;
287
	}
323
	}
288
324
289
	sprintf(stmt, "insert into %s (", table_ce.u.string);
325
	snprintf(stmt, stmt_siz, "insert into %s (", table_ce.u.string);
290
	stmt_val = stmt + strlen(stmt);
326
	stmt_val = stmt + strlen(stmt);
291
327
292
	for (f = fields; f; f = f->next) {
328
	for (f = fields; f; f = f->next) {
293
		strncpy(buf, f->name, ULOGD_MAX_KEYLEN);	
329
		strncpy(buf, f->name, ULOGD_MAX_KEYLEN-1);
330
		buf[ULOGD_MAX_KEYLEN-1] = '\0';
294
		while ((underscore = strchr(buf, '.')))
331
		while ((underscore = strchr(buf, '.')))
295
			*underscore = '_';
332
			*underscore = '_';
296
		sprintf(stmt_val, "%s,", buf);
333
		STMT_ADD(stmt_val,"%s,", buf);
297
		stmt_val = stmt + strlen(stmt);
334
		stmt_val = stmt + strlen(stmt);
298
	}
335
	}
299
	*(stmt_val - 1) = ')';
336
	*(stmt_val - 1) = ')';
300
337
301
	sprintf(stmt_val, " values (");
338
	STMT_ADD(stmt_val," values (");
302
	stmt_val = stmt + strlen(stmt);
339
	stmt_val = stmt + strlen(stmt);
303
340
304
	ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt);
341
	ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt);
Lines 333-339 Link Here
333
	while ((field = mysql_fetch_field(result))) {
370
	while ((field = mysql_fetch_field(result))) {
334
371
335
		/* replace all underscores with dots */
372
		/* replace all underscores with dots */
336
		strncpy(buf, field->name, ULOGD_MAX_KEYLEN);
373
		strncpy(buf, field->name, ULOGD_MAX_KEYLEN-1);
374
		buf[ULOGD_MAX_KEYLEN-1] = '\0';
375
337
		while ((underscore = strchr(buf, '_')))
376
		while ((underscore = strchr(buf, '_')))
338
			*underscore = '.';
377
			*underscore = '.';
339
378
Lines 352-359 Link Here
352
			ulogd_log(ULOGD_ERROR, "OOM!\n");
391
			ulogd_log(ULOGD_ERROR, "OOM!\n");
353
			return -1;
392
			return -1;
354
		}
393
		}
355
		strncpy(f->name, buf, ULOGD_MAX_KEYLEN);
394
		strncpy(f->name, buf, ULOGD_MAX_KEYLEN-1);
395
		f->name[ULOGD_MAX_KEYLEN-1] = '\0';
356
		f->id = id;
396
		f->id = id;
397
		f->str = !IS_NUM(field->type);
357
		f->next = fields;
398
		f->next = fields;
358
		fields = f;	
399
		fields = f;	
359
	}
400
	}
Lines 366-380 Link Here
366
static int mysql_open_db(char *server, int port, char *user, char *pass, 
407
static int mysql_open_db(char *server, int port, char *user, char *pass, 
367
			 char *db)
408
			 char *db)
368
{
409
{
410
#ifdef MYSQL_OPT_RECONNECT
411
	my_bool trueval = 1;
412
#endif 
369
	dbh = mysql_init(NULL);
413
	dbh = mysql_init(NULL);
370
	if (!dbh)
414
	if (!dbh)
371
		return -1;
415
		return -1;
372
416
373
	if (connect_timeout_ce.u.value)
417
	if (connect_timeout_ce.u.value)
374
		mysql_options(dbh, MYSQL_OPT_CONNECT_TIMEOUT, (const char *) &connect_timeout_ce.u.value);
418
		mysql_options(dbh, MYSQL_OPT_CONNECT_TIMEOUT,
419
			(const char *) &connect_timeout_ce.u.value);
420
421
#ifdef MYSQL_OPT_RECONNECT
422
#  if defined(MYSQL_VERSION_ID) && (MYSQL_VERSION_ID >= 50019)
423
	mysql_options(dbh, MYSQL_OPT_RECONNECT, &trueval);
424
#  endif
425
#endif 
426
375
427
376
	if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0))
428
	if (!mysql_real_connect(dbh, server, user, pass, db, port, NULL, 0))
429
	{
430
		_mysql_fini();
377
		return -1;
431
		return -1;
432
	}
433
434
#ifdef MYSQL_OPT_RECONNECT
435
#  if defined(MYSQL_VERSION_ID) && (MYSQL_VERSION_ID < 50019)
436
	mysql_options(dbh, MYSQL_OPT_RECONNECT, &trueval);
437
#  endif
438
#endif
378
439
379
	return 0;
440
	return 0;
380
}
441
}
Lines 413-422 Link Here
413
	/* read the fieldnames to know which values to insert */
474
	/* read the fieldnames to know which values to insert */
414
	if (mysql_get_columns(table_ce.u.string)) {
475
	if (mysql_get_columns(table_ce.u.string)) {
415
		ulogd_log(ULOGD_ERROR, "unable to get mysql columns\n");
476
		ulogd_log(ULOGD_ERROR, "unable to get mysql columns\n");
477
		_mysql_fini();
416
		return init_reconnect();
478
		return init_reconnect();
417
	}
479
	}
418
	mysql_createstmt();
480
419
	
481
	if (mysql_createstmt())
482
	{
483
		ulogd_log(ULOGD_ERROR, "unable to create mysql statement\n");
484
		_mysql_fini();
485
		return init_reconnect();
486
	}
487
420
	/* enable plugin */
488
	/* enable plugin */
421
	mysql_plugin.output = &mysql_output;
489
	mysql_plugin.output = &mysql_output;
422
490
Lines 438-444 Link Here
438
506
439
static void _mysql_fini(void)
507
static void _mysql_fini(void)
440
{
508
{
441
	mysql_close(dbh);
509
	if (dbh) {
510
		mysql_close(dbh);
511
		dbh = NULL;
512
	}
442
}
513
}
443
514
444
static ulog_output_t mysql_plugin = { 
515
static ulog_output_t mysql_plugin = { 
(-)pcap/ulogd_PCAP.c (-3 / +3 lines)
Lines 158-164 Link Here
158
		return 1;
158
		return 1;
159
	}
159
	}
160
160
161
	if (pcapf_ce.u.value)
161
	if (pcapsync_ce.u.value)
162
		fflush(of);
162
		fflush(of);
163
163
164
	return 0;
164
	return 0;
Lines 217-224 Link Here
217
	if (!exist) {
217
	if (!exist) {
218
		of = fopen(pcapf_ce.u.string, "w");
218
		of = fopen(pcapf_ce.u.string, "w");
219
		if (!of) {
219
		if (!of) {
220
			ulogd_log(ULOGD_FATAL, "can't open pcap file: %s\n",
220
			ulogd_log(ULOGD_FATAL, "can't open pcap file %s: %s\n",
221
				  strerror(errno));
221
				  pcapf_ce.u.string, strerror(errno));
222
			exit(2);
222
			exit(2);
223
		}
223
		}
224
		if (!write_pcap_header()) {
224
		if (!write_pcap_header()) {
(-)pgsql/ulogd_PGSQL.c (-57 / +136 lines)
Lines 16-22 Link Here
16
#include <ulogd/ulogd.h>
16
#include <ulogd/ulogd.h>
17
#include <ulogd/conffile.h>
17
#include <ulogd/conffile.h>
18
#include <libpq-fe.h>
18
#include <libpq-fe.h>
19
19
#include <inttypes.h>
20
20
21
#ifdef DEBUG_PGSQL
21
#ifdef DEBUG_PGSQL
22
#define DEBUGP(x, args...)	fprintf(stderr, x, ## args)
22
#define DEBUGP(x, args...)	fprintf(stderr, x, ## args)
Lines 27-32 Link Here
27
struct _field {
27
struct _field {
28
	char name[ULOGD_MAX_KEYLEN];
28
	char name[ULOGD_MAX_KEYLEN];
29
	unsigned int id;
29
	unsigned int id;
30
	unsigned int str;
30
	struct _field *next;
31
	struct _field *next;
31
};
32
};
32
33
Lines 39-44 Link Here
39
/* buffer for our insert statement */
40
/* buffer for our insert statement */
40
static char *stmt;
41
static char *stmt;
41
42
43
/* size of our insert statement buffer */
44
static size_t stmt_siz;
45
42
/* pointer to the beginning of the "VALUES" part */
46
/* pointer to the beginning of the "VALUES" part */
43
static char *stmt_val;
47
static char *stmt_val;
44
48
Lines 97-102 Link Here
97
101
98
static unsigned char pgsql_have_schemas;
102
static unsigned char pgsql_have_schemas;
99
103
104
#define STMT_ADD(pos,fmt...) \
105
	do { \
106
		if ((pos) >= stmt && stmt_siz > (pos) - stmt) \
107
			snprintf((pos), stmt_siz-((pos)-stmt), ##fmt); \
108
	} while(0)
109
100
/* our main output function, called by ulogd */
110
/* our main output function, called by ulogd */
101
static int pgsql_output(ulog_iret_t *result)
111
static int pgsql_output(ulog_iret_t *result)
102
{
112
{
Lines 107-112 Link Here
107
	char *tmpstr;		/* need this for --log-ip-as-string */
117
	char *tmpstr;		/* need this for --log-ip-as-string */
108
	struct in_addr addr;
118
	struct in_addr addr;
109
#endif
119
#endif
120
	size_t esclen;
121
122
	if( stmt_val == NULL)
123
		return 1;
110
124
111
	stmt_ins = stmt_val;
125
	stmt_ins = stmt_val;
112
126
Lines 120-181 Link Here
120
134
121
		if (!res || !IS_VALID((*res))) {
135
		if (!res || !IS_VALID((*res))) {
122
			/* no result, we have to fake something */
136
			/* no result, we have to fake something */
123
			sprintf(stmt_ins, "NULL,");
137
			STMT_ADD(stmt_ins, "NULL,");
124
			stmt_ins = stmt + strlen(stmt);
138
			stmt_ins = stmt + strlen(stmt);
125
			continue;
139
			continue;
126
		}
140
		}
127
141
128
		switch (res->type) {
142
		switch (res->type) {
129
			case ULOGD_RET_INT8:
143
			case ULOGD_RET_INT8:
130
				sprintf(stmt_ins, "%d,", res->value.i8);
144
				STMT_ADD(stmt_ins, "%d,", res->value.i8);
131
				break;
145
				break;
132
			case ULOGD_RET_INT16:
146
			case ULOGD_RET_INT16:
133
				sprintf(stmt_ins, "%d,", res->value.i16);
147
				STMT_ADD(stmt_ins, "%d,", res->value.i16);
134
				break;
148
				break;
135
			case ULOGD_RET_INT32:
149
			case ULOGD_RET_INT32:
136
				sprintf(stmt_ins, "%d,", res->value.i32);
150
				STMT_ADD(stmt_ins, "%d,", res->value.i32);
137
				break;
151
				break;
138
			case ULOGD_RET_INT64:
152
			case ULOGD_RET_INT64:
139
				sprintf(stmt_ins, "%lld,", res->value.i64);
153
				STMT_ADD(stmt_ins, "%"PRId64",",res->value.i64);
140
				break;
154
				break;
141
			case ULOGD_RET_UINT8:
155
			case ULOGD_RET_UINT8:
142
				sprintf(stmt_ins, "%u,", res->value.ui8);
156
				STMT_ADD(stmt_ins, "%u,", res->value.ui8);
143
				break;
157
				break;
144
			case ULOGD_RET_UINT16:
158
			case ULOGD_RET_UINT16:
145
				sprintf(stmt_ins, "%u,", res->value.ui16);
159
				STMT_ADD(stmt_ins, "%u,", res->value.ui16);
146
				break;
160
				break;
147
			case ULOGD_RET_IPADDR:
161
			case ULOGD_RET_IPADDR:
148
#ifdef IP_AS_STRING
162
#ifdef IP_AS_STRING
149
				*stmt_ins++ = '\'';
163
				if (f->str) {
150
				memset(&addr, 0, sizeof(addr));
164
					addr.s_addr = ntohl(res->value.ui32);
151
				addr.s_addr = ntohl(res->value.ui32);
165
					tmpstr = (char *)inet_ntoa(addr);
152
				tmpstr = (char *)inet_ntoa(addr);
166
					esclen = (strlen(tmpstr)*2) + 4;
153
				PQescapeString(stmt_ins,tmpstr,strlen(tmpstr)); 
167
					if (stmt_siz <= (stmt_ins-stmt)+esclen)
154
				stmt_ins = stmt + strlen(stmt);
168
					{
155
				sprintf(stmt_ins, "',");
169
						STMT_ADD(stmt_ins,"'',");
156
				break;
170
						break;
171
					}
172
					*stmt_ins++ = '\'';
173
					PQescapeString(stmt_ins,tmpstr,
174
							strlen(tmpstr)); 
175
					stmt_ins = stmt + strlen(stmt);
176
					STMT_ADD(stmt_ins, "',");
177
					break;
178
				}
157
#endif /* IP_AS_STRING */
179
#endif /* IP_AS_STRING */
158
				/* EVIL: fallthrough when logging IP as
180
				/* EVIL: fallthrough when logging IP as
159
				 * u_int32_t */
181
				 * u_int32_t */
160
182
161
			case ULOGD_RET_UINT32:
183
			case ULOGD_RET_UINT32:
162
				sprintf(stmt_ins, "%u,", res->value.ui32);
184
				STMT_ADD(stmt_ins, "%u,", res->value.ui32);
163
				break;
185
				break;
164
			case ULOGD_RET_UINT64:
186
			case ULOGD_RET_UINT64:
165
				sprintf(stmt_ins, "%llu,", res->value.ui64);
187
				STMT_ADD(stmt_ins,"%"PRIu64",",res->value.ui64);
166
				break;
188
				break;
167
			case ULOGD_RET_BOOL:
189
			case ULOGD_RET_BOOL:
168
				sprintf(stmt_ins, "'%d',", res->value.b);
190
				STMT_ADD(stmt_ins, "'%d',", res->value.b);
169
				break;
191
				break;
170
			case ULOGD_RET_STRING:
192
			case ULOGD_RET_STRING:
193
				esclen = (strlen(res->value.ptr)*2) + 4;
194
				if (stmt_siz <= (stmt_ins-stmt) + esclen) {
195
					STMT_ADD(stmt_ins, "'',");
196
					break;
197
				}
171
				*stmt_ins++ = '\'';
198
				*stmt_ins++ = '\'';
172
				PQescapeString(stmt_ins,res->value.ptr,strlen(res->value.ptr)); 
199
				PQescapeString(stmt_ins,res->value.ptr,
200
						strlen(res->value.ptr)); 
173
				stmt_ins = stmt + strlen(stmt);
201
				stmt_ins = stmt + strlen(stmt);
174
				sprintf(stmt_ins, "',");
202
				STMT_ADD(stmt_ins, "',");
175
				break;
203
				break;
176
			case ULOGD_RET_RAW:
204
			case ULOGD_RET_RAW:
177
				ulogd_log(ULOGD_NOTICE,"%s: pgsql doesn't support type RAW\n",res->key);
205
				ulogd_log(ULOGD_NOTICE,
178
				sprintf(stmt_ins, "NULL,");
206
					"%s: pgsql doesn't support type RAW\n",
207
					res->key);
208
				STMT_ADD(stmt_ins, "NULL,");
179
				break;
209
				break;
180
			default:
210
			default:
181
				ulogd_log(ULOGD_NOTICE,
211
				ulogd_log(ULOGD_NOTICE,
Lines 186-191 Link Here
186
		stmt_ins = stmt + strlen(stmt);
216
		stmt_ins = stmt + strlen(stmt);
187
	}
217
	}
188
	*(stmt_ins - 1) = ')';
218
	*(stmt_ins - 1) = ')';
219
189
	DEBUGP("stmt=#%s#\n", stmt);
220
	DEBUGP("stmt=#%s#\n", stmt);
190
221
191
	/* now we have created our statement, insert it */
222
	/* now we have created our statement, insert it */
Lines 202-218 Link Here
202
	return 0;
233
	return 0;
203
}
234
}
204
235
205
#define PGSQL_HAVE_NAMESPACE_TEMPLATE "SELECT nspname FROM pg_namespace n WHERE n.nspname='%s'"
236
#define PGSQL_HAVE_NAMESPACE_TEMPLATE \
237
	"SELECT nspname FROM pg_namespace n WHERE n.nspname='%s'"
206
238
207
/* Determine if server support schemas */
239
/* Determine if server support schemas */
208
static int pgsql_namespace(void) {
240
static int pgsql_namespace(void) {
209
	PGresult *result;
241
	PGresult *result;
210
	char pgbuf[strlen(PGSQL_HAVE_NAMESPACE_TEMPLATE)+strlen(schema_ce.u.string)+1];
242
	char pgbuf[strlen(PGSQL_HAVE_NAMESPACE_TEMPLATE)+
243
		   	strlen(schema_ce.u.string)+1];
211
244
212
	if (!dbh)
245
	if (!dbh)
213
		return 1;
246
		return 1;
214
247
215
	sprintf(pgbuf, PGSQL_HAVE_NAMESPACE_TEMPLATE, schema_ce.u.string);
248
	snprintf(pgbuf, sizeof(pgbuf), PGSQL_HAVE_NAMESPACE_TEMPLATE,
249
			schema_ce.u.string);
216
	ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf);
250
	ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf);
217
	
251
	
218
	result = PQexec(dbh, pgbuf);
252
	result = PQexec(dbh, pgbuf);
Lines 240-246 Link Here
240
static int pgsql_createstmt(void)
274
static int pgsql_createstmt(void)
241
{
275
{
242
	struct _field *f;
276
	struct _field *f;
243
	unsigned int size;
244
	char buf[ULOGD_MAX_KEYLEN];
277
	char buf[ULOGD_MAX_KEYLEN];
245
	char *underscore;
278
	char *underscore;
246
279
Lines 251-291 Link Here
251
	}
284
	}
252
285
253
	/* caclulate the size for the insert statement */
286
	/* caclulate the size for the insert statement */
254
	size = strlen(PGSQL_INSERTTEMPL) + strlen(table_ce.u.string) + strlen(schema_ce.u.string) + 1;
287
	stmt_siz = strlen(PGSQL_INSERTTEMPL) +
288
		   strlen(table_ce.u.string) +
289
		   strlen(schema_ce.u.string) + 1;
255
290
256
	for (f = fields; f; f = f->next) {
291
	for (f = fields; f; f = f->next) {
257
		/* we need space for the key and a comma, as well as
292
		/* we need space for the key and a comma, as well as
258
		 * enough space for the values */
293
		 * enough space for the values */
259
		size += strlen(f->name) + 1 + PGSQL_VALSIZE;
294
		stmt_siz += strlen(f->name) + 1 + PGSQL_VALSIZE;
260
	}
295
	}
261
296
262
	ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", size);
297
	ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", stmt_siz);
263
298
264
	stmt = (char *) malloc(size);
299
	stmt = (char *) malloc(stmt_siz);
265
300
266
	if (!stmt) {
301
	if (!stmt) {
302
		stmt_siz = 0;
267
		ulogd_log(ULOGD_ERROR, "OOM!\n");
303
		ulogd_log(ULOGD_ERROR, "OOM!\n");
268
		return 1;
304
		return 1;
269
	}
305
	}
270
306
271
	if (pgsql_have_schemas) {
307
	if (pgsql_have_schemas) {
272
		sprintf(stmt, "insert into %s.%s (", schema_ce.u.string, table_ce.u.string);
308
		snprintf(stmt, stmt_siz, "insert into %s.%s (",
309
			schema_ce.u.string, table_ce.u.string);
273
	} else {
310
	} else {
274
		sprintf(stmt, "insert into %s (", table_ce.u.string);
311
		snprintf(stmt, stmt_siz, "insert into %s (",
312
			table_ce.u.string);
275
	}
313
	}
276
314
277
	stmt_val = stmt + strlen(stmt);
315
	stmt_val = stmt + strlen(stmt);
278
316
279
	for (f = fields; f; f = f->next) {
317
	for (f = fields; f; f = f->next) {
280
		strncpy(buf, f->name, ULOGD_MAX_KEYLEN);
318
		strncpy(buf, f->name, ULOGD_MAX_KEYLEN-1);
319
		buf[ULOGD_MAX_KEYLEN-1] = '\0';
281
		while ((underscore = strchr(buf, '.')))
320
		while ((underscore = strchr(buf, '.')))
282
			*underscore = '_';
321
			*underscore = '_';
283
		sprintf(stmt_val, "%s,", buf);
322
		STMT_ADD(stmt_val, "%s,", buf);
284
		stmt_val = stmt + strlen(stmt);
323
		stmt_val = stmt + strlen(stmt);
285
	}
324
	}
286
	*(stmt_val - 1) = ')';
325
	*(stmt_val - 1) = ')';
287
326
288
	sprintf(stmt_val, " values (");
327
	STMT_ADD(stmt_val, " values (");
289
	stmt_val = stmt + strlen(stmt);
328
	stmt_val = stmt + strlen(stmt);
290
329
291
	ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt);
330
	ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt);
Lines 293-320 Link Here
293
	return 0;
332
	return 0;
294
}
333
}
295
334
296
#define PGSQL_GETCOLUMN_TEMPLATE "SELECT  a.attname FROM pg_class c, pg_attribute a WHERE c.relname ='%s' AND a.attnum>0 AND a.attrelid=c.oid ORDER BY a.attnum"
335
#define PGSQL_GETCOLUMN_TEMPLATE \
297
336
	"SELECT  a.attname,t.typname FROM pg_class c, pg_attribute a, "\
298
#define PGSQL_GETCOLUMN_TEMPLATE_SCHEMA "SELECT a.attname FROM pg_attribute a, pg_class c LEFT JOIN pg_namespace n ON c.relnamespace=n.oid WHERE c.relname ='%s' AND n.nspname='%s' AND a.attnum>0 AND a.attrelid=c.oid AND a.attisdropped=FALSE ORDER BY a.attnum"
337
	"pg_type t WHERE c.relname ='%s' AND a.attnum>0 AND a.attrelid="\
338
	"c.oid AND a.atttypid=t.oid ORDER BY a.attnum"
339
340
#define PGSQL_GETCOLUMN_TEMPLATE_SCHEMA "SELECT a.attname,t.typname FROM "\
341
	"pg_attribute a, pg_type t, pg_class c LEFT JOIN pg_namespace n ON "\
342
	"c.relnamespace=n.oid WHERE c.relname ='%s' AND n.nspname='%s' AND "\
343
	"a.attnum>0 AND a.attrelid=c.oid AND a.atttypid=t.oid AND "\
344
	"a.attisdropped=FALSE ORDER BY a.attnum"
299
345
300
/* find out which columns the table has */
346
/* find out which columns the table has */
301
static int pgsql_get_columns(const char *table)
347
static int pgsql_get_columns(const char *table)
302
{
348
{
303
	PGresult *result;
349
	PGresult *result;
304
	char buf[ULOGD_MAX_KEYLEN];
350
	char buf[ULOGD_MAX_KEYLEN];
305
	char pgbuf[strlen(PGSQL_GETCOLUMN_TEMPLATE_SCHEMA)+strlen(table)+strlen(schema_ce.u.string)+2];
351
	char pgbuf[strlen(PGSQL_GETCOLUMN_TEMPLATE_SCHEMA)+
352
		   strlen(table)+strlen(schema_ce.u.string)+2];
306
	char *underscore;
353
	char *underscore;
307
	struct _field *f;
354
	struct _field *f;
308
	int id;
355
	int id;
309
	int intaux;
356
	int intaux;
357
	char *typename;
310
358
311
	if (!dbh)
359
	if (!dbh)
312
		return 1;
360
		return 1;
313
361
314
	if (pgsql_have_schemas) {
362
	if (pgsql_have_schemas) {
315
		snprintf(pgbuf, sizeof(pgbuf)-1, PGSQL_GETCOLUMN_TEMPLATE_SCHEMA, table, schema_ce.u.string);
363
		snprintf(pgbuf, sizeof(pgbuf)-1,
364
			PGSQL_GETCOLUMN_TEMPLATE_SCHEMA,
365
			table, schema_ce.u.string);
316
	} else {
366
	} else {
317
		snprintf(pgbuf, sizeof(pgbuf)-1, PGSQL_GETCOLUMN_TEMPLATE, table);
367
		snprintf(pgbuf, sizeof(pgbuf)-1,
368
			PGSQL_GETCOLUMN_TEMPLATE, table);
318
	}
369
	}
319
370
320
	ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf);
371
	ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf);
Lines 333-339 Link Here
333
	for (intaux=0; intaux<PQntuples(result); intaux++) {
384
	for (intaux=0; intaux<PQntuples(result); intaux++) {
334
385
335
		/* replace all underscores with dots */
386
		/* replace all underscores with dots */
336
		strncpy(buf, PQgetvalue(result, intaux, 0), ULOGD_MAX_KEYLEN);
387
		strncpy(buf, PQgetvalue(result, intaux, 0), ULOGD_MAX_KEYLEN-1);
388
		buf[ULOGD_MAX_KEYLEN-1] = '\0';
337
		while ((underscore = strchr(buf, '_')))
389
		while ((underscore = strchr(buf, '_')))
338
			*underscore = '.';
390
			*underscore = '.';
339
391
Lines 352-359 Link Here
352
			ulogd_log(ULOGD_ERROR, "OOM!\n");
404
			ulogd_log(ULOGD_ERROR, "OOM!\n");
353
			return 1;
405
			return 1;
354
		}
406
		}
355
		strncpy(f->name, buf, ULOGD_MAX_KEYLEN);
407
		strncpy(f->name, buf, ULOGD_MAX_KEYLEN-1);
408
		f->name[ULOGD_MAX_KEYLEN-1] = '\0';
356
		f->id = id;
409
		f->id = id;
410
		f->str = 0;
411
		if( (typename = PQgetvalue(result, intaux, 1)) != NULL)
412
		{
413
			if(strcmp(typename, "inet") == 0 ||
414
			   strstr(typename, "char") != NULL)
415
				f->str = 1;
416
		}
357
		f->next = fields;
417
		f->next = fields;
358
		fields = f;
418
		fields = f;
359
	}
419
	}
Lines 386-419 Link Here
386
	if (port)
446
	if (port)
387
		len += 20;
447
		len += 20;
388
448
389
	connstr = (char *) malloc(len);
449
	connstr = (char *) malloc(len+1);
390
	if (!connstr)
450
	if (!connstr)
391
		return 1;
451
		return 1;
452
	*connstr = '\0';
392
453
393
	if (server) {
454
	if (server) {
394
		strcpy(connstr, " host=");
455
		strncat(connstr, " host=", len-strlen(connstr));
395
		strcat(connstr, server);
456
		strncat(connstr, server, len-strlen(connstr));
396
	}
457
	}
397
458
398
	if (port) {
459
	if (port) {
399
		char portbuf[20];
460
		char portbuf[20];
400
		snprintf(portbuf, sizeof(portbuf), " port=%u", port);
461
		snprintf(portbuf, sizeof(portbuf), " port=%u", port);
401
		strcat(connstr, portbuf);
462
		strncat(connstr, portbuf, len-strlen(connstr));
402
	}
463
	}
403
464
404
	strcat(connstr, " dbname=");
465
	strncat(connstr, " dbname=", len-strlen(connstr));
405
	strcat(connstr, db);
466
	strncat(connstr, db, len-strlen(connstr));
406
	strcat(connstr, " user=");
467
	strncat(connstr, " user=", len-strlen(connstr));
407
	strcat(connstr, user);
468
	strncat(connstr, user, len-strlen(connstr));
408
469
409
	if (pass) {
470
	if (pass) {
410
		strcat(connstr, " password=");
471
		strncat(connstr, " password=", len-strlen(connstr));
411
		strcat(connstr, pass);
472
		strncat(connstr, pass, len-strlen(connstr));
412
	}
473
	}
413
	
474
	
414
	dbh = PQconnectdb(connstr);
475
	dbh = PQconnectdb(connstr);
476
	free(connstr);
415
	if (PQstatus(dbh)!=CONNECTION_OK) {
477
	if (PQstatus(dbh)!=CONNECTION_OK) {
416
		exit_nicely(dbh);
478
		exit_nicely(dbh);
479
		dbh = NULL;
417
		return 1;
480
		return 1;
418
	}
481
	}
419
482
Lines 432-454 Link Here
432
	}
495
	}
433
496
434
	if (pgsql_namespace()) {
497
	if (pgsql_namespace()) {
435
		return 1;
498
		PQfinish(dbh);
499
		dbh = NULL;
436
		ulogd_log(ULOGD_ERROR, "unable to test for pgsql schemas\n");
500
		ulogd_log(ULOGD_ERROR, "unable to test for pgsql schemas\n");
501
		return 1;
437
	}
502
	}
438
503
439
	/* read the fieldnames to know which values to insert */
504
	/* read the fieldnames to know which values to insert */
440
	if (pgsql_get_columns(table_ce.u.string)) {
505
	if (pgsql_get_columns(table_ce.u.string)) {
506
		PQfinish(dbh);
507
		dbh = NULL;
441
		ulogd_log(ULOGD_ERROR, "unable to get pgsql columns\n");
508
		ulogd_log(ULOGD_ERROR, "unable to get pgsql columns\n");
442
		return 1;
509
		return 1;
443
	}
510
	}
444
	pgsql_createstmt();
511
512
	if (pgsql_createstmt()) {
513
		PQfinish(dbh);
514
		dbh = NULL;
515
		return 1;
516
	}
445
517
446
	return 0;
518
	return 0;
447
}
519
}
448
520
449
static void pgsql_fini(void)
521
static void pgsql_fini(void)
450
{
522
{
451
	PQfinish(dbh);
523
	if (dbh)
524
		PQfinish(dbh);
525
	if (stmt)
526
	{
527
		free(stmt);
528
		stmt = NULL;
529
		stmt_val = NULL;
530
	}
452
}
531
}
453
532
454
static ulog_output_t pgsql_plugin = { 
533
static ulog_output_t pgsql_plugin = { 
(-)Rules.make.in (-9 / +10 lines)
Lines 20-29 Link Here
20
20
21
CFLAGS=@CFLAGS@ @CPPFLAGS@ -Wall
21
CFLAGS=@CFLAGS@ @CPPFLAGS@ -Wall
22
CFLAGS+=-DULOGD_CONFIGFILE=\"$(ULOGD_CONFIGFILE)\"
22
CFLAGS+=-DULOGD_CONFIGFILE=\"$(ULOGD_CONFIGFILE)\"
23
CFLAGS+=@KERNEL64_USERSPACE32@
23
# doesn't work for subdirs
24
# doesn't work for subdirs
24
#CFLAGS+=$(INCIPULOG) $(INCCONFFILE)
25
CFLAGS+=$(INCIPULOG)
25
CFLAGS+=-I/lib/modules/`uname -r`/build/include
26
#CFLAGS+=-I/lib/modules/`uname -r`/build/include
26
#CFLAGS+=@DEFS@
27
CFLAGS+=@DEFS@
27
#CFLAGS+=-g -DDEBUG -DDEBUG_MYSQL -DDEBUG_PGSQL
28
#CFLAGS+=-g -DDEBUG -DDEBUG_MYSQL -DDEBUG_PGSQL
28
29
29
LIBS=@LIBS@
30
LIBS=@LIBS@
Lines 34-49 Link Here
34
35
35
# mysql output support
36
# mysql output support
36
#ULOGD_SL+=MYSQL
37
#ULOGD_SL+=MYSQL
37
MYSQL_CFLAGS=-I@MYSQLINCLUDES@ @EXTRA_MYSQL_DEF@
38
MYSQL_CFLAGS=@MYSQLINCLUDES@ @EXTRA_MYSQL_DEF@
38
MYSQL_LDFLAGS=@DATABASE_LIB_DIR@ @MYSQL_LIB@
39
MYSQL_LDFLAGS=$(LDFLAGS) @MYSQL_LIB@
39
40
40
# postgreSQL output support
41
# postgreSQL output support
41
#ULOGD_SL+=PGSQL
42
#ULOGD_SL+=PGSQL
42
PGSQL_CFLAGS=-I@PGSQLINCLUDES@ @EXTRA_PGSQL_DEF@
43
PGSQL_CFLAGS=@PGSQLINCLUDES@ @EXTRA_PGSQL_DEF@
43
PGSQL_LDFLAGS=@DATABASE_LIB_DIR@ @PGSQL_LIB@
44
PGSQL_LDFLAGS=$(LDFLAGS) @PGSQL_LIB@
44
45
45
# mysql output support
46
# mysql output support
46
#ULOGD_SL+=SQLITE3
47
#ULOGD_SL+=SQLITE3
47
SQLITE3_CFLAGS=-I@SQLITE3INCLUDES@ @EXTRA_SQLITE3_DEF@
48
SQLITE3_CFLAGS=@SQLITE3INCLUDES@ @EXTRA_SQLITE3_DEF@
48
SQLITE3_LDFLAGS=@DATABASE_LIB_DIR@ @SQLITE3_LIB@
49
SQLITE3_LDFLAGS=$(LDFLAGS) @SQLITE3_LIB@
49
50
(-)sqlite3/ulogd_SQLITE3.c (-25 / +48 lines)
Lines 55-60 Link Here
55
/* buffer for our insert statement */
55
/* buffer for our insert statement */
56
static char *stmt;
56
static char *stmt;
57
57
58
/* size of our insert statement buffer */
59
static size_t stmt_siz;
60
58
/* pointer to the final prepared statement */
61
/* pointer to the final prepared statement */
59
static sqlite3_stmt *p_stmt;
62
static sqlite3_stmt *p_stmt;
60
63
Lines 85-90 Link Here
85
	.options = CONFIG_OPT_MANDATORY,
88
	.options = CONFIG_OPT_MANDATORY,
86
};
89
};
87
90
91
#define STMT_ADD(pos,beg,siz,fmt...) \
92
	do { \
93
		if((pos) >= (beg) && (siz) > (pos) - (beg)) \
94
			snprintf((pos), (siz)-((pos)-(beg)), ##fmt); \
95
	} while(0)
96
88
/* our main output function, called by ulogd */
97
/* our main output function, called by ulogd */
89
static int _sqlite3_output(ulog_iret_t *result)
98
static int _sqlite3_output(ulog_iret_t *result)
90
{
99
{
Lines 96-101 Link Here
96
	struct in_addr addr;
105
	struct in_addr addr;
97
#endif
106
#endif
98
107
108
	if (p_stmt == NULL || dbh == NULL)
109
		return 1;
110
99
	col_counter = 1;
111
	col_counter = 1;
100
	for (f = fields; f; f = f->next) {
112
	for (f = fields; f; f = f->next) {
101
		res = keyh_getres(f->id);
113
		res = keyh_getres(f->id);
Lines 136-142 Link Here
136
				memset(&addr, 0, sizeof(addr));
148
				memset(&addr, 0, sizeof(addr));
137
				addr.s_addr = ntohl(res->value.ui32);
149
				addr.s_addr = ntohl(res->value.ui32);
138
				ipaddr = inet_ntoa(addr);
150
				ipaddr = inet_ntoa(addr);
139
				sqlite3_bind_text(p_stmt,col_counter,ipaddr,strlen(ipaddr),SQLITE_STATIC);
151
				sqlite3_bind_text(p_stmt,col_counter,ipaddr,strlen(ipaddr),SQLITE_TRANSIENT);
140
                                break;
152
                                break;
141
#endif /* IP_AS_STRING */
153
#endif /* IP_AS_STRING */
142
			/* EVIL: fallthrough when logging IP as u_int32_t */
154
			/* EVIL: fallthrough when logging IP as u_int32_t */
Lines 194-200 Link Here
194
static int _sqlite3_createstmt(void)
206
static int _sqlite3_createstmt(void)
195
{
207
{
196
	struct _field *f;
208
	struct _field *f;
197
	unsigned int size;
198
	char buf[ULOGD_MAX_KEYLEN];
209
	char buf[ULOGD_MAX_KEYLEN];
199
	char *underscore;
210
	char *underscore;
200
	char *stmt_pos;
211
	char *stmt_pos;
Lines 208-272 Link Here
208
	}
219
	}
209
220
210
	/* caclulate the size for the insert statement */
221
	/* caclulate the size for the insert statement */
211
	size = strlen(_SQLITE3_INSERTTEMPL) + strlen(table_ce.u.string);
222
	stmt_siz = strlen(_SQLITE3_INSERTTEMPL) + strlen(table_ce.u.string);
212
223
213
	DEBUGP("initial size: %u\n", size);
224
	DEBUGP("initial size: %zu\n", stmt_siz);
214
225
215
	col_count = 0;
226
	col_count = 0;
216
	for (f = fields; f; f = f->next) {
227
	for (f = fields; f; f = f->next) {
217
		/* we need space for the key and a comma, and a ? */
228
		/* we need space for the key and a comma, and a ? */
218
		size += strlen(f->name) + 3;
229
		stmt_siz += strlen(f->name) + 3;
219
		DEBUGP("size is now %u since adding %s\n",size,f->name);
230
		DEBUGP("size is now %zu since adding %s\n",stmt_siz,f->name);
220
		col_count++;
231
		col_count++;
221
	}
232
	}
222
233
223
	DEBUGP("there were %d columns\n",col_count);
234
	DEBUGP("there were %d columns\n",col_count);
224
	DEBUGP("after calc name length: %u\n",size);
235
	DEBUGP("after calc name length: %zu\n",stmt_siz);
225
236
226
	ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", size);
237
	ulogd_log(ULOGD_DEBUG, "allocating %zu bytes for statement\n", stmt_siz);
227
238
228
	stmt = (char *) malloc(size);
239
	stmt = (char *) malloc(stmt_siz);
229
240
230
	if (!stmt) {
241
	if (!stmt) {
242
		stmt_siz = 0;
231
		ulogd_log(ULOGD_ERROR, "OOM!\n");
243
		ulogd_log(ULOGD_ERROR, "OOM!\n");
232
		return 1;
244
		return 1;
233
	}
245
	}
234
246
235
	sprintf(stmt, "insert into %s (", table_ce.u.string);
247
	snprintf(stmt, stmt_siz, "insert into %s (", table_ce.u.string);
236
	stmt_pos = stmt + strlen(stmt);
248
	stmt_pos = stmt + strlen(stmt);
237
249
238
	for (f = fields; f; f = f->next) {
250
	for (f = fields; f; f = f->next) {
239
		strncpy(buf, f->name, ULOGD_MAX_KEYLEN);	
251
		strncpy(buf, f->name, ULOGD_MAX_KEYLEN-1);
252
		buf[ULOGD_MAX_KEYLEN-1] = '\0';
240
		while ((underscore = strchr(buf, '.')))
253
		while ((underscore = strchr(buf, '.')))
241
			*underscore = '_';
254
			*underscore = '_';
242
		sprintf(stmt_pos, "%s,", buf);
255
		STMT_ADD(stmt_pos,stmt,stmt_siz, "%s,", buf);
243
		stmt_pos = stmt + strlen(stmt);
256
		stmt_pos = stmt + strlen(stmt);
244
	}
257
	}
245
258
246
	*(stmt_pos - 1) = ')';
259
	*(stmt_pos - 1) = ')';
247
260
248
	sprintf(stmt_pos, " values (");
261
	STMT_ADD(stmt_pos,stmt,stmt_siz, " values (");
249
	stmt_pos = stmt + strlen(stmt);
262
	stmt_pos = stmt + strlen(stmt);
250
263
251
	for (i = 0; i < col_count - 1; i++) {
264
	for (i = 0; i < col_count - 1; i++) {
252
		sprintf(stmt_pos,"?,");
265
		STMT_ADD(stmt_pos,stmt,stmt_siz, "?,");
253
		stmt_pos += 2;
266
		stmt_pos += 2;
254
	}
267
	}
255
268
256
	sprintf(stmt_pos, "?)");
269
	STMT_ADD(stmt_pos,stmt,stmt_siz, "?)");
257
	ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt);
270
	ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt);
258
271
259
	DEBUGP("about to prepare statement.\n");
272
	DEBUGP("about to prepare statement.\n");
260
273
261
	sqlite3_prepare(dbh,stmt,-1,&p_stmt,0);
274
	if (sqlite3_prepare(dbh,stmt,-1,&p_stmt,0) != SQLITE_OK) {
262
275
		p_stmt = NULL;
263
	DEBUGP("statement prepared.\n");
276
		free( stmt);
264
277
		stmt = stmt_pos = NULL;
265
	if (!p_stmt) {
266
		ulogd_log(ULOGD_ERROR,"unable to prepare statement");
278
		ulogd_log(ULOGD_ERROR,"unable to prepare statement");
267
		return 1;
279
		return 1;
268
	}
280
	}
269
281
282
	DEBUGP("statement prepared.\n");
283
270
	return 0;
284
	return 0;
271
}
285
}
272
286
Lines 278-284 Link Here
278
static int _sqlite3_get_columns(const char *table)
292
static int _sqlite3_get_columns(const char *table)
279
{
293
{
280
	char buf[ULOGD_MAX_KEYLEN];
294
	char buf[ULOGD_MAX_KEYLEN];
281
	char query[SQLITE_SELECT_LEN + CONFIG_VAL_STRING_LEN] = "select * from \0";
295
	char query[SQLITE_SELECT_LEN + CONFIG_VAL_STRING_LEN + 1] = "select * from \0";
282
	char *underscore;
296
	char *underscore;
283
	struct _field *f;
297
	struct _field *f;
284
	sqlite3_stmt *schema_stmt;
298
	sqlite3_stmt *schema_stmt;
Lines 289-295 Link Here
289
	if (!dbh)
303
	if (!dbh)
290
		return 1;
304
		return 1;
291
305
292
	strncat(query,table,LINE_LEN);
306
	strncat(query,table,sizeof(query)-strlen(query)-1);
293
	
307
	
294
	result = sqlite3_prepare(dbh,query,-1,&schema_stmt,0);
308
	result = sqlite3_prepare(dbh,query,-1,&schema_stmt,0);
295
	
309
	
Lines 298-304 Link Here
298
312
299
	for (column = 0; column < sqlite3_column_count(schema_stmt); column++) {
313
	for (column = 0; column < sqlite3_column_count(schema_stmt); column++) {
300
		/* replace all underscores with dots */
314
		/* replace all underscores with dots */
301
		strncpy(buf, sqlite3_column_name(schema_stmt,column), ULOGD_MAX_KEYLEN);
315
		strncpy(buf, sqlite3_column_name(schema_stmt,column), ULOGD_MAX_KEYLEN-1);
316
		buf[ULOGD_MAX_KEYLEN-1] = '\0';
302
		while ((underscore = strchr(buf, '_')))
317
		while ((underscore = strchr(buf, '_')))
303
			*underscore = '.';
318
			*underscore = '.';
304
319
Lines 317-323 Link Here
317
			ulogd_log(ULOGD_ERROR, "OOM!\n");
332
			ulogd_log(ULOGD_ERROR, "OOM!\n");
318
			return 1;
333
			return 1;
319
		}
334
		}
320
		strncpy(f->name, buf, ULOGD_MAX_KEYLEN);
335
		strncpy(f->name, buf, ULOGD_MAX_KEYLEN-1);
336
		f->name[ULOGD_MAX_KEYLEN-1] = '\0';
321
		f->id = id;
337
		f->id = id;
322
		f->next = fields;
338
		f->next = fields;
323
		fields = f;	
339
		fields = f;	
Lines 357-362 Link Here
357
			ulogd_log(ULOGD_ERROR,"unable to commit remaining records to db.");
373
			ulogd_log(ULOGD_ERROR,"unable to commit remaining records to db.");
358
374
359
		sqlite3_close(dbh);
375
		sqlite3_close(dbh);
376
		dbh = NULL;
360
		DEBUGP("database file closed\n");
377
		DEBUGP("database file closed\n");
361
	}
378
	}
362
}
379
}
Lines 379-384 Link Here
379
396
380
	/* read the fieldnames to know which values to insert */
397
	/* read the fieldnames to know which values to insert */
381
	if (_sqlite3_get_columns(table_ce.u.string)) {
398
	if (_sqlite3_get_columns(table_ce.u.string)) {
399
		sqlite3_close(dbh);
400
		dbh = NULL;
382
		ulogd_log(ULOGD_ERROR, "unable to get sqlite columns\n");
401
		ulogd_log(ULOGD_ERROR, "unable to get sqlite columns\n");
383
		return 1;
402
		return 1;
384
	}
403
	}
Lines 393-399 Link Here
393
		ulogd_log(ULOGD_ERROR,"can't create a new transaction\n");
412
		ulogd_log(ULOGD_ERROR,"can't create a new transaction\n");
394
413
395
	/* create and prepare the actual insert statement */
414
	/* create and prepare the actual insert statement */
396
	_sqlite3_createstmt();
415
	if(_sqlite3_createstmt()) {
416
		sqlite3_close(dbh);
417
		dbh = NULL;
418
		return 1;
419
	}
397
420
398
	return 0;
421
	return 0;
399
}
422
}
(-)ulogd.c (-9 / +39 lines)
Lines 37-43 Link Here
37
 * 		- added suppurt for seteuid()
37
 * 		- added suppurt for seteuid()
38
 */
38
 */
39
39
40
#define ULOGD_VERSION	"1.23"
40
#define ULOGD_VERSION	"1.24"
41
41
42
#include <unistd.h>
42
#include <unistd.h>
43
#include <stdio.h>
43
#include <stdio.h>
Lines 87-92 Link Here
87
#define ULOGD_CONFIGFILE	"/etc/ulogd.conf"
87
#define ULOGD_CONFIGFILE	"/etc/ulogd.conf"
88
#endif
88
#endif
89
89
90
/* default user to run as or "" */
91
#ifndef ULOGD_USER_DEFAULT
92
#define ULOGD_USER_DEFAULT	""
93
#endif
94
90
/* global variables */
95
/* global variables */
91
static struct ipulog_handle *libulog_h;	/* our libipulog handle */
96
static struct ipulog_handle *libulog_h;	/* our libipulog handle */
92
static unsigned char* libulog_buf;	/* the receive buffer */
97
static unsigned char* libulog_buf;	/* the receive buffer */
Lines 474-480 Link Here
474
	} else if (!strcmp(name,"stdout"))
479
	} else if (!strcmp(name,"stdout"))
475
		logfile = stdout;
480
		logfile = stdout;
476
	else {
481
	else {
477
		logfile = fopen(name, "a");
482
		logfile = fopen64(name, "a");
478
		if (!logfile) {
483
		if (!logfile) {
479
			fprintf(stderr, "ERROR: can't open logfile %s: %s\n", 
484
			fprintf(stderr, "ERROR: can't open logfile %s: %s\n", 
480
				name, strerror(errno));
485
				name, strerror(errno));
Lines 545-551 Link Here
545
static config_entry_t loglevel_ce = { &nlgroup_ce, "loglevel", CONFIG_TYPE_INT,
550
static config_entry_t loglevel_ce = { &nlgroup_ce, "loglevel", CONFIG_TYPE_INT,
546
				      CONFIG_OPT_NONE, 0, 
551
				      CONFIG_OPT_NONE, 0, 
547
				      { value: ULOGD_NOTICE } };
552
				      { value: ULOGD_NOTICE } };
548
static config_entry_t rmem_ce = { &loglevel_ce, "rmem", CONFIG_TYPE_INT,
553
554
static config_entry_t user_ce = { &loglevel_ce, "user", CONFIG_TYPE_STRING,
555
				  CONFIG_OPT_NONE, 0,
556
				  { string: ULOGD_USER_DEFAULT } };
557
558
static config_entry_t rmem_ce = { &user_ce, "rmem", CONFIG_TYPE_INT,
549
				  CONFIG_OPT_NONE, 0, 
559
				  CONFIG_OPT_NONE, 0, 
550
				  { value: ULOGD_RMEM_DEFAULT } };
560
				  { value: ULOGD_RMEM_DEFAULT } };
551
561
Lines 595-608 Link Here
595
605
596
	ipulog_destroy_handle(libulog_h);
606
	ipulog_destroy_handle(libulog_h);
597
	free(libulog_buf);
607
	free(libulog_buf);
598
	if (logfile != stdout && logfile != &syslog_dummy)
599
		fclose(logfile);
600
608
601
	for (p = ulogd_outputs; p; p = p->next) {
609
	for (p = ulogd_outputs; p; p = p->next) {
602
		if (p->fini)
610
		if (p->fini)
603
			(*p->fini)();
611
			(*p->fini)();
604
	}
612
	}
605
613
614
	if (logfile != stdout && logfile != &syslog_dummy)
615
		fclose(logfile);
616
606
	exit(0);
617
	exit(0);
607
}
618
}
608
619
Lines 612-618 Link Here
612
623
613
	if (logfile != stdout && logfile != &syslog_dummy) {
624
	if (logfile != stdout && logfile != &syslog_dummy) {
614
		fclose(logfile);
625
		fclose(logfile);
615
		logfile = fopen(logf_ce.u.string, "a");
626
		logfile = fopen64(logf_ce.u.string, "a");
616
		if (!logfile)
627
		if (!logfile)
617
			sigterm_handler(signal);
628
			sigterm_handler(signal);
618
	}
629
	}
Lines 629-635 Link Here
629
{
640
{
630
	/* FIXME */
641
	/* FIXME */
631
	printf("ulogd Version %s\n", ULOGD_VERSION);
642
	printf("ulogd Version %s\n", ULOGD_VERSION);
632
	printf("Copyright (C) 2000-2005 Harald Welte "
643
	printf("Copyright (C) 2000-2008 Harald Welte "
633
	       "<laforge@gnumonks.org>\n");
644
	       "<laforge@gnumonks.org>\n");
634
	printf("This is free software with ABSOLUTELY NO WARRANTY.\n\n");
645
	printf("This is free software with ABSOLUTELY NO WARRANTY.\n\n");
635
	printf("Parameters:\n");
646
	printf("Parameters:\n");
Lines 684-690 Link Here
684
			break;
695
			break;
685
		case 'V':
696
		case 'V':
686
			printf("ulogd Version %s\n", ULOGD_VERSION);
697
			printf("ulogd Version %s\n", ULOGD_VERSION);
687
			printf("Copyright (C) 2000-2005 Harald Welte "
698
			printf("Copyright (C) 2000-2008 Harald Welte "
688
			       "<laforge@gnumonks.org>\n");
699
			       "<laforge@gnumonks.org>\n");
689
			exit(0);
700
			exit(0);
690
			break;
701
			break;
Lines 694-707 Link Here
694
		case 'u':
705
		case 'u':
695
			change_uid = 1;
706
			change_uid = 1;
696
			user = strdup(optarg);
707
			user = strdup(optarg);
708
			setpwent();
697
			pw = getpwnam(user);
709
			pw = getpwnam(user);
698
			if (!pw) {
710
			if (!pw) {
699
				printf("Unknown user %s.\n", user);
711
				printf("Unknown user %s.\n", user);
712
				endpwent();
700
				free(user);
713
				free(user);
701
				exit(1);
714
				exit(1);
702
			}
715
			}
703
			uid = pw->pw_uid;
716
			uid = pw->pw_uid;
704
			gid = pw->pw_gid;
717
			gid = pw->pw_gid;
718
			endpwent();
705
			break;
719
			break;
706
		}
720
		}
707
	}
721
	}
Lines 739-745 Link Here
739
		exit(1);
753
		exit(1);
740
	}
754
	}
741
755
742
756
	/* if no -u cmd line option set, read the user option from config. */
757
	if (!change_uid && strlen(user_ce.u.string))
758
	{
759
		change_uid = 1;
760
		user = strdup(user_ce.u.string);
761
		setpwent();
762
		pw = getpwnam(user);
763
		if (!pw) {
764
			printf("Unknown user %s.\n", user);
765
			endpwent();
766
			free(user);
767
			exit(1);
768
		}
769
		uid = pw->pw_uid;
770
		gid = pw->pw_gid;
771
		endpwent();
772
	}
743
	if (change_uid) {
773
	if (change_uid) {
744
		ulogd_log(ULOGD_NOTICE, "Changing UID / GID\n");
774
		ulogd_log(ULOGD_NOTICE, "Changing UID / GID\n");
745
		if (setgid(gid)) {
775
		if (setgid(gid)) {
(-)ulogd.conf.in (-5 / +8 lines)
Lines 7-17 Link Here
7
# GLOBAL OPTIONS
7
# GLOBAL OPTIONS
8
######################################################################
8
######################################################################
9
9
10
# username to run as (runs as root if not set)
11
user=ulogd
12
10
# netlink multicast group (the same as the iptables --ulog-nlgroup param)
13
# netlink multicast group (the same as the iptables --ulog-nlgroup param)
11
nlgroup=1
14
nlgroup=1
12
15
13
# logfile for status messages
16
# logfile for status messages
14
logfile="/var/log/ulogd.log"
17
logfile="/var/log/ulogd/ulogd.log"
15
18
16
# loglevel: debug(1), info(3), notice(5), error(7) or fatal(8)
19
# loglevel: debug(1), info(3), notice(5), error(7) or fatal(8)
17
loglevel=5
20
loglevel=5
Lines 50-60 Link Here
50
53
51
54
52
[LOGEMU]
55
[LOGEMU]
53
file="/var/log/ulogd.syslogemu"
56
file="/var/log/ulogd/ulogd.syslogemu"
54
sync=1
57
sync=1
55
58
56
[OPRINT]
59
[OPRINT]
57
file="/var/log/ulogd.pktlog"
60
file="/var/log/ulogd/ulogd.pktlog"
58
61
59
[MYSQL]
62
[MYSQL]
60
table="ulog"
63
table="ulog"
Lines 73-82 Link Here
73
76
74
[SQLITE3]
77
[SQLITE3]
75
table="ulog"
78
table="ulog"
76
db="/path/to/sqlite/db"
79
db="/var/log/ulogd/sqlite3.db"
77
buffer=200
80
buffer=200
78
81
79
[PCAP]
82
[PCAP]
80
file="/var/log/ulogd.pcap"
83
file="/var/log/ulogd/ulogd.pcap"
81
sync=1
84
sync=1
82
85
(-)configure.in.orig (-59 / +67 lines)
Lines 1-4 Link Here
1
dnl Process this file with autoconf to produce a configure script.
1
dnl Process this file with autoconf to produce a configure script.
2
AC_PREQ(2.50)
2
AC_INIT(ulogd.c)
3
AC_INIT(ulogd.c)
3
4
4
dnl Checks for programs.
5
dnl Checks for programs.
Lines 20-25 Link Here
20
AC_C_CONST
21
AC_C_CONST
21
AC_TYPE_SIZE_T
22
AC_TYPE_SIZE_T
22
AC_STRUCT_TM
23
AC_STRUCT_TM
24
AC_SYS_LARGEFILE
23
25
24
dnl Checks for library functions.
26
dnl Checks for library functions.
25
AC_FUNC_VPRINTF
27
AC_FUNC_VPRINTF
Lines 31-47 Link Here
31
33
32
DATABASE_DRIVERS=""
34
DATABASE_DRIVERS=""
33
35
36
KERNEL64_USERSPACE32=""
37
34
dnl
38
dnl
35
dnl test for MySQL
39
dnl test for MySQL
36
dnl
40
dnl
37
AC_ARG_WITH(mysql,
41
AC_ARG_WITH(mysql, AS_HELP_STRING([--with-mysql=<directory>],[mysql installed in <directory>]),[with_mysql=$withval],[with_mysql=no])
38
 --with-mysql=<directory>		mysql installed in <directory>,[
42
if test "$withval" != yes ; then
39
if test $withval != yes
43
    if test "$withval" != no ; then
40
then
41
        dir=$withval
44
        dir=$withval
42
else
45
    else
43
        dir="/usr/local"
46
        dir="/usr/local"
47
    fi
44
fi
48
fi
49
50
if test "$withval" != no ; then
45
mysqldir=""
51
mysqldir=""
46
AC_MSG_CHECKING(for MySQL files)
52
AC_MSG_CHECKING(for MySQL files)
47
for d in $dir/bin /usr/bin /usr/local/bin /usr/local/mysql/bin /opt/mysql/bin /opt/packages/mysql/bin
53
for d in $dir/bin /usr/bin /usr/local/bin /usr/local/mysql/bin /opt/mysql/bin /opt/packages/mysql/bin
Lines 60-74 Link Here
60
else
66
else
61
        AC_DEFINE(HAVE_MYSQL)
67
        AC_DEFINE(HAVE_MYSQL)
62
        MYSQLINCLUDES=`$d/mysql_config --include`
68
        MYSQLINCLUDES=`$d/mysql_config --include`
63
        MYSQLLIBS=`$d/mysql_config --libs`
64
69
65
	DATABASE_DIR="${DATABASE_DIR} mysql"
70
	DATABASE_DIR="${DATABASE_DIR} mysql"
66
71
67
	MYSQL_LIB="${DATABASE_LIB} ${MYSQLLIBS} " 
72
	MYSQL_LIB=`$d/mysql_config --libs`
68
	# no change to DATABASE_LIB_DIR, since --libs already includes -L
69
70
	DATABASE_DRIVERS="${DATABASE_DRIVERS} ../mysql/mysql_driver.o "
71
72
	DB_DEF="${DB_DEF} -DHAVE_MYSQL "
73
	DB_DEF="${DB_DEF} -DHAVE_MYSQL "
73
74
74
75
Lines 81-100 Link Here
81
	dnl Having a look in the libary itself should be more reliable than
82
	dnl Having a look in the libary itself should be more reliable than
82
	dnl parsing the output of mysql --version.
83
	dnl parsing the output of mysql --version.
83
84
84
	AC_MSG_CHECKING(for mysql_real_escape_string support)
85
	OLDLIBS="$LIBS"
85
86
	LIBS="$MYSQL_LIB"
86
	MYSQL_FUNCTION_TEST=`strings ${MYSQLLIBS}/libmysqlclient.so | grep mysql_real_escape_string`
87
	AC_CHECK_FUNCS([mysql_real_escape_string], [], [EXTRA_MYSQL_DEF="-DOLD_MYSQL=1 "])
87
88
	LIBS="$OLDLIBS"
88
	if test "x$MYSQL_FUNCTION_TEST" = x
89
fi      
89
	then
90
                EXTRA_MYSQL_DEF="-DOLD_MYSQL=1 "
91
                AC_MSG_RESULT(found old MySQL)
92
	else
93
		AC_MSG_RESULT(found new MySQL)
94
	fi
95
96
fi      
90
fi      
97
])      
98
91
99
92
100
dnl
93
dnl
Lines 116-129 Link Here
116
dnl
109
dnl
117
dnl test for PostgreSQL
110
dnl test for PostgreSQL
118
dnl
111
dnl
119
AC_ARG_WITH(pgsql,
112
AC_ARG_WITH(pgsql, AS_HELP_STRING([--with-pgsql=<directory>],[pgsql installed in <directory>]),[with_pgsql=$withval],[with_pgsql=no])
120
 --with-pgsql=<directory>		pgsql installed in <directory>,[
113
if test "$withval" != yes ; then
121
if test $withval != yes
114
    if test "$withval" != no ; then
122
then
123
        dir=$withval
115
        dir=$withval
124
else
116
    else
125
        dir="/usr/local"
117
        dir="/usr/local"
118
    fi
126
fi
119
fi
120
if test "$withval" != no ; then
127
pgsqldir=""
121
pgsqldir=""
128
AC_MSG_CHECKING(for PGSQL files)
122
AC_MSG_CHECKING(for PGSQL files)
129
for d in $dir/bin /usr/bin /usr/local/bin /usr/local/pgsql/bin /opt/pgsql/bin /opt/packages/pgsql/bin
123
for d in $dir/bin /usr/bin /usr/local/bin /usr/local/pgsql/bin /opt/pgsql/bin /opt/packages/pgsql/bin
Lines 141-160 Link Here
141
        AC_MSG_WARN(PGSQL backend not used)
135
        AC_MSG_WARN(PGSQL backend not used)
142
else
136
else
143
        AC_DEFINE(HAVE_PGSQL)
137
        AC_DEFINE(HAVE_PGSQL)
144
	PGSQLINCLUDES=`$pgsqldir/pg_config --includedir`
138
	PGSQLINCLUDES=-I`$pgsqldir/pg_config --includedir`
145
	PGSQLLIBS=`$pgsqldir/pg_config --libdir`
139
	PGSQLLIBS=-L`$pgsqldir/pg_config --libdir`
146
140
147
	DATABASE_DIR="${DATABASE_DIR} pgsql"
141
	DATABASE_DIR="${DATABASE_DIR} pgsql"
148
	PGSQL_LIB="${DATABASE_LIB} -lpq " 
142
	PGSQL_LIB="${PGSQLLIBS} -lpq " 
149
143
150
	DATABASE_LIB_DIR="${DATABASE_LIB_DIR} -L${PGSQLLIBS} "
151
	DB_DEF="${DB_DEF} -DHAVE_PGSQL "
144
	DB_DEF="${DB_DEF} -DHAVE_PGSQL "
152
145
153
	AC_SUBST(PGSQLINCLUDES)
146
	AC_SUBST(PGSQLINCLUDES)
154
	AC_SUBST(PGSQL_LIB)
147
	AC_SUBST(PGSQL_LIB)
155
148
156
fi      
149
fi      
157
])      
150
fi      
158
151
159
dnl
152
dnl
160
dnl Check whether the user wants to log IP-addresses as strings rather
153
dnl Check whether the user wants to log IP-addresses as strings rather
Lines 171-212 Link Here
171
dnl
164
dnl
172
dnl test for sqlite3
165
dnl test for sqlite3
173
dnl
166
dnl
174
AC_ARG_WITH(sqlite3,
167
AC_ARG_WITH(sqlite3, AS_HELP_STRING([--with-sqlite3=<directory>],[sqlite3 installed in <directory>]),[with_sqlite3=$withval],[with_sqlite3=no])
175
 --with-sqlite3=<directory>		sqlite3 installed in <directory>,[
168
if test "$withval" != yes ; then
176
if test $withval != yes
169
    if test "$withval" != no ; then
177
then
178
        dir=$withval
170
        dir=$withval
179
else
171
    else
180
        dir="/usr/local"
172
        dir="/usr/local"
173
    fi
181
fi
174
fi
182
mysqldir=""
175
if test "$withval" != no ; then
176
sqlite3dir=""
183
AC_MSG_CHECKING(for sqlite3 files)
177
AC_MSG_CHECKING(for sqlite3 files)
184
for d in $dir /usr /usr/local /usr/local/sqlite3
178
for d in $dir /usr /usr/local /usr/local/sqlite3
185
do
179
do
186
        if test -f $d/lib/sqlite3/libsqlite3.so
180
	if test -f $d/lib64/sqlite3/libsqlite3.so
187
        then
188
                AC_MSG_RESULT(found sqlite3 in $d)
189
                sqlite3dir=$d
190
                sqlite3dir_suffix=/sqlite3
191
                break
192
	elif test -f $d/lib64/sqlite3/libsqlite3.so
193
	then
181
	then
194
		AC_MSG_RESULT(found sqlite3 in $d)
182
		AC_MSG_RESULT(found sqlite3 in $d)
195
		sqlite3dir=$d
183
		sqlite3dir=$d
196
		sqlite3dir_suffix=/sqlite3
184
		sqlite3dir_suffix=/sqlite3
185
		sqlite3dir_libdir=${sqlite3dir}/lib64
197
		break
186
		break
198
        elif test -f $d/lib/libsqlite3.so
187
        elif test -f $d/lib/sqlite3/libsqlite3.so
199
        then
188
        then
200
                AC_MSG_RESULT(found sqlite in $d)
189
                AC_MSG_RESULT(found sqlite3 in $d)
201
                sqlite3dir=$d
190
                sqlite3dir=$d
202
                sqlite3dir_suffix=
191
                sqlite3dir_suffix=/sqlite3
192
		sqlite3dir_libdir=${sqlite3dir}/lib
203
                break
193
                break
204
	elif test -f $d/lib64/libsqlite3.so
194
	elif test -f $d/lib64/libsqlite3.so
205
        then
195
        then
206
		AC_MSG_RESULT(found sqlite in $d)
196
		AC_MSG_RESULT(found sqlite3 in $d)
207
		sqlite3dir=$d
197
		sqlite3dir=$d
208
		sqlite3dir_suffix=
198
		sqlite3dir_suffix=
199
		sqlite3dir_libdir=${sqlite3dir}/lib64
209
		break
200
		break
201
        elif test -f $d/lib/libsqlite3.so
202
        then
203
                AC_MSG_RESULT(found sqlite3 in $d)
204
                sqlite3dir=$d
205
                sqlite3dir_suffix=
206
		sqlite3dir_libdir=${sqlite3dir}/lib
207
                break
210
        fi
208
        fi
211
done
209
done
212
210
Lines 215-229 Link Here
215
        AC_MSG_WARN(sqlite3 backend not used)
213
        AC_MSG_WARN(sqlite3 backend not used)
216
else
214
else
217
        AC_DEFINE(HAVE_SQLITE3)
215
        AC_DEFINE(HAVE_SQLITE3)
218
        SQLITE3INCLUDES=${sqlite3dir}/include${sqlite3dir_suffix}
216
        SQLITE3INCLUDES=-I${sqlite3dir}/include${sqlite3dir_suffix}
219
        SQLITE3LIBS=${sqlite3dir}/lib${sqlite3dir_suffix}
217
        SQLITE3LIBS=-L${sqlite3dir_libdir}${sqlite3dir_suffix}
220
218
221
	DATABASE_DIR="${DATABASE_DIR} sqlite3"
219
	DATABASE_DIR="${DATABASE_DIR} sqlite3"
222
220
	SQLITE3_LIB="${SQLITE3LIBS} -lsqlite3 " 
223
	SQLITE3_LIB="${DATABASE_LIB} -lsqlite3 " 
224
	DATABASE_LIB_DIR="${DATABASE_LIB_DIR} -L${SQLITE3LIBS} "
225
226
dnl	DATABASE_DRIVERS="${DATABASE_DRIVERS} ../sqlite3/mysql_driver.o "
227
221
228
	DB_DEF="${DB_DEF} -DHAVE_SQLITE3 "
222
	DB_DEF="${DB_DEF} -DHAVE_SQLITE3 "
229
223
Lines 232-238 Link Here
232
	AC_SUBST(SQLITE3_LIB)
226
	AC_SUBST(SQLITE3_LIB)
233
227
234
fi      
228
fi      
235
])      
229
fi      
236
230
237
231
238
dnl
232
dnl
Lines 250-255 Link Here
250
   AC_MSG_WARN(the use of --with-sqlite3-log-ip-as-string is discouraged)
244
   AC_MSG_WARN(the use of --with-sqlite3-log-ip-as-string is discouraged)
251
])
245
])
252
246
247
dnl
248
dnl Kernel 64
249
dnl
250
251
AC_ARG_WITH(kernel-64-user-32,
252
 --with-kernel-64-user-32		Use this flag to compile on system where kernel is 64 bits
253
					userspace is 32.
254
,[
255
   KERNEL64_USERSPACE32="-DKERNEL_64_USERSPACE_32"
256
   AC_MSG_WARN(The use of the flag kernel-64-user-32 could interfere with kernel evolution. Use it at your own risk.)
257
])
258
253
259
254
AC_SUBST(DATABASE_DIR)
260
AC_SUBST(DATABASE_DIR)
255
AC_SUBST(DATABASE_LIB)
261
AC_SUBST(DATABASE_LIB)
Lines 262-267 Link Here
262
AC_SUBST(DATABASE_DRIVERS)
268
AC_SUBST(DATABASE_DRIVERS)
263
AC_SUBST(HAVE_PCAP_H)
269
AC_SUBST(HAVE_PCAP_H)
264
270
271
AC_SUBST(KERNEL64_USERSPACE32)
272
265
AM_CONDITIONAL(HAVE_MYSQL, test x$mysqldir != x)
273
AM_CONDITIONAL(HAVE_MYSQL, test x$mysqldir != x)
266
AM_CONDITIONAL(HAVE_PGSQL, test x$pgsqldir != x)
274
AM_CONDITIONAL(HAVE_PGSQL, test x$pgsqldir != x)
267
AM_CONDITIONAL(HAVE_SQLITE3, test x$sqlite3dir != x)
275
AM_CONDITIONAL(HAVE_SQLITE3, test x$sqlite3dir != x)

Return to bug 225363