Line
Link Here
|
|
-- extensions/printpkt.c |
|
|
Lines 95-107
static struct intr_id intr_ids[INTR_IDS]
Link Here
|
95 |
#define GET_VALUE(x) ulogd_keyh[intr_ids[x].id].interp->result[ulogd_keyh[intr_ids[x].id].offset].value |
95 |
#define GET_VALUE(x) ulogd_keyh[intr_ids[x].id].interp->result[ulogd_keyh[intr_ids[x].id].offset].value |
96 |
#define GET_FLAGS(x) ulogd_keyh[intr_ids[x].id].interp->result[ulogd_keyh[intr_ids[x].id].offset].flags |
96 |
#define GET_FLAGS(x) ulogd_keyh[intr_ids[x].id].interp->result[ulogd_keyh[intr_ids[x].id].offset].flags |
97 |
|
97 |
|
98 |
int printpkt_print(ulog_iret_t *res, char *buf, int prefix) |
98 |
int printpkt_print(ulog_iret_t *res, char *buf, size_t buf_siz, int prefix) |
99 |
{ |
99 |
{ |
100 |
char *timestr; |
100 |
char *timestr; |
101 |
char *tmp; |
101 |
char *tmp; |
102 |
time_t now; |
102 |
time_t now; |
103 |
|
103 |
|
104 |
char *buf_cur = buf; |
104 |
if( buf_siz) *buf = '\0'; |
|
|
105 |
size_t buf_len = 0; |
106 |
|
107 |
#define BUF_ADD(ptr, siz, off, fmt...) \ |
108 |
snprintf(((ptr)+(off)), ((siz) > (off) ? (siz)-(off) : 0), ##fmt) |
105 |
|
109 |
|
106 |
if (prefix) { |
110 |
if (prefix) { |
107 |
now = (time_t) GET_VALUE(0).ui32; |
111 |
now = (time_t) GET_VALUE(0).ui32; |
Lines 116-242
int printpkt_print(ulog_iret_t *res, cha
Link Here
|
116 |
*tmp = '\0'; |
120 |
*tmp = '\0'; |
117 |
|
121 |
|
118 |
/* print time and hostname */ |
122 |
/* print time and hostname */ |
119 |
buf_cur += sprintf(buf_cur, "%.15s %s", timestr, hostname); |
123 |
buf_len = strlen(buf); |
|
|
124 |
BUF_ADD(buf,buf_siz,buf_len, "%.15s %s", timestr, hostname); |
120 |
} |
125 |
} |
121 |
|
126 |
|
122 |
if (*(char *) GET_VALUE(1).ptr) |
127 |
if (*(char *) GET_VALUE(1).ptr) |
123 |
buf_cur += sprintf(buf_cur, " %s", (char *) GET_VALUE(1).ptr); |
128 |
{ |
|
|
129 |
buf_len = strlen(buf); |
130 |
BUF_ADD(buf,buf_siz,buf_len, " %s", (char *) GET_VALUE(1).ptr); |
131 |
} |
124 |
|
132 |
|
125 |
buf_cur += sprintf(buf_cur," IN=%s OUT=%s ", |
133 |
buf_len = strlen(buf); |
126 |
(char *) GET_VALUE(2).ptr, |
134 |
BUF_ADD(buf,buf_siz,buf_len," IN=%s OUT=%s ", |
127 |
(char *) GET_VALUE(3).ptr); |
135 |
(char *) GET_VALUE(2).ptr, |
|
|
136 |
(char *) GET_VALUE(3).ptr); |
128 |
|
137 |
|
129 |
/* FIXME: configurable */ |
138 |
/* FIXME: configurable */ |
130 |
buf_cur += sprintf(buf_cur, "MAC=%s ", |
139 |
buf_len = strlen(buf); |
131 |
(GET_FLAGS(4) & ULOGD_RETF_VALID) ? (char *) GET_VALUE(4).ptr : ""); |
140 |
BUF_ADD(buf,buf_siz,buf_len, "MAC=%s ", |
132 |
|
141 |
(GET_FLAGS(4) & ULOGD_RETF_VALID) ? (char *) GET_VALUE(4).ptr : ""); |
133 |
buf_cur += sprintf(buf_cur, "SRC=%s ", |
142 |
|
134 |
inet_ntoa((struct in_addr) {htonl(GET_VALUE(5).ui32)})); |
143 |
buf_len = strlen(buf); |
135 |
buf_cur += sprintf(buf_cur, "DST=%s ", |
144 |
BUF_ADD(buf,buf_siz,buf_len, "SRC=%s ", |
136 |
inet_ntoa((struct in_addr) {htonl(GET_VALUE(6).ui32)})); |
145 |
inet_ntoa((struct in_addr) {htonl(GET_VALUE(5).ui32)})); |
137 |
|
146 |
|
138 |
buf_cur += sprintf(buf_cur,"LEN=%u TOS=%02X PREC=0x%02X TTL=%u ID=%u ", |
147 |
buf_len = strlen(buf); |
139 |
GET_VALUE(7).ui16, GET_VALUE(8).ui8 & IPTOS_TOS_MASK, |
148 |
BUF_ADD(buf,buf_siz,buf_len, "DST=%s ", |
140 |
GET_VALUE(8).ui8 & IPTOS_PREC_MASK, GET_VALUE(9).ui8, |
149 |
inet_ntoa((struct in_addr) {htonl(GET_VALUE(6).ui32)})); |
141 |
GET_VALUE(10).ui16); |
150 |
|
|
|
151 |
buf_len = strlen(buf); |
152 |
BUF_ADD(buf,buf_siz,buf_len, |
153 |
"LEN=%u TOS=%02X PREC=0x%02X TTL=%u ID=%u ", |
154 |
GET_VALUE(7).ui16, GET_VALUE(8).ui8 & IPTOS_TOS_MASK, |
155 |
GET_VALUE(8).ui8 & IPTOS_PREC_MASK, GET_VALUE(9).ui8, |
156 |
GET_VALUE(10).ui16); |
142 |
|
157 |
|
143 |
if (GET_VALUE(10).ui16 & IP_RF) |
158 |
if (GET_VALUE(10).ui16 & IP_RF) |
144 |
buf_cur += sprintf(buf_cur, "CE "); |
159 |
{ |
|
|
160 |
buf_len = strlen(buf); |
161 |
BUF_ADD(buf,buf_siz,buf_len, "CE "); |
162 |
} |
145 |
|
163 |
|
146 |
if (GET_VALUE(11).ui16 & IP_DF) |
164 |
if (GET_VALUE(11).ui16 & IP_DF) |
147 |
buf_cur += sprintf(buf_cur, "DF "); |
165 |
{ |
|
|
166 |
buf_len = strlen(buf); |
167 |
BUF_ADD(buf,buf_siz,buf_len, "DF "); |
168 |
} |
148 |
|
169 |
|
149 |
if (GET_VALUE(11).ui16 & IP_MF) |
170 |
if (GET_VALUE(11).ui16 & IP_MF) |
150 |
buf_cur += sprintf(buf_cur, "MF "); |
171 |
{ |
|
|
172 |
buf_len = strlen(buf); |
173 |
BUF_ADD(buf,buf_siz,buf_len, "MF "); |
174 |
} |
151 |
|
175 |
|
152 |
if (GET_VALUE(11).ui16 & IP_OFFMASK) |
176 |
if (GET_VALUE(11).ui16 & IP_OFFMASK) |
153 |
buf_cur += sprintf(buf_cur, "FRAG:%u ", |
177 |
{ |
|
|
178 |
buf_len = strlen(buf); |
179 |
BUF_ADD(buf,buf_siz,buf_len, "FRAG:%u ", |
154 |
GET_VALUE(11).ui16 & IP_OFFMASK); |
180 |
GET_VALUE(11).ui16 & IP_OFFMASK); |
|
|
181 |
} |
155 |
|
182 |
|
156 |
switch (GET_VALUE(12).ui8) { |
183 |
switch (GET_VALUE(12).ui8) { |
157 |
|
184 |
|
158 |
case IPPROTO_TCP: |
185 |
case IPPROTO_TCP: |
159 |
buf_cur += sprintf(buf_cur, "PROTO=TCP "); |
186 |
buf_len = strlen(buf); |
160 |
buf_cur += sprintf(buf_cur, "SPT=%u DPT=%u ", |
187 |
BUF_ADD(buf,buf_siz,buf_len, "PROTO=TCP "); |
161 |
GET_VALUE(13).ui16, GET_VALUE(14).ui16); |
188 |
buf_len = strlen(buf); |
|
|
189 |
BUF_ADD(buf,buf_siz,buf_len, "SPT=%u DPT=%u ", |
190 |
GET_VALUE(13).ui16, GET_VALUE(14).ui16); |
162 |
/* FIXME: config */ |
191 |
/* FIXME: config */ |
163 |
buf_cur += sprintf(buf_cur, "SEQ=%u ACK=%u ", |
192 |
buf_len = strlen(buf); |
164 |
GET_VALUE(15).ui32, GET_VALUE(16).ui32); |
193 |
BUF_ADD(buf,buf_siz,buf_len, "SEQ=%u ACK=%u ", |
165 |
|
194 |
GET_VALUE(15).ui32, GET_VALUE(16).ui32); |
166 |
buf_cur += sprintf(buf_cur, "WINDOW=%u ", GET_VALUE(17).ui16); |
195 |
|
|
|
196 |
buf_len = strlen(buf); |
197 |
BUF_ADD(buf,buf_siz,buf_len, |
198 |
"WINDOW=%u ", GET_VALUE(17).ui16); |
167 |
|
199 |
|
168 |
// buf_cur += sprintf(buf_cur, "RES=0x%02x ", |
200 |
// buf_len = strlen(buf); |
|
|
201 |
// BUF_ADD(buf,buf_siz,buf_len, "RES=0x%02x ", |
169 |
|
202 |
|
170 |
if (GET_VALUE(18).b) |
203 |
if (GET_VALUE(18).b) |
171 |
buf_cur += sprintf(buf_cur, "URG "); |
204 |
{ |
|
|
205 |
buf_len = strlen(buf); |
206 |
BUF_ADD(buf,buf_siz,buf_len, "URG "); |
207 |
} |
172 |
|
208 |
|
173 |
if (GET_VALUE(19).b) |
209 |
if (GET_VALUE(19).b) |
174 |
buf_cur += sprintf(buf_cur, "ACK "); |
210 |
{ |
|
|
211 |
buf_len = strlen(buf); |
212 |
BUF_ADD(buf,buf_siz,buf_len, "ACK "); |
213 |
} |
175 |
|
214 |
|
176 |
if (GET_VALUE(20).b) |
215 |
if (GET_VALUE(20).b) |
177 |
buf_cur += sprintf(buf_cur, "PSH "); |
216 |
{ |
|
|
217 |
buf_len = strlen(buf); |
218 |
BUF_ADD(buf,buf_siz,buf_len, "PSH "); |
219 |
} |
178 |
|
220 |
|
179 |
if (GET_VALUE(21).b) |
221 |
if (GET_VALUE(21).b) |
180 |
buf_cur += sprintf(buf_cur, "RST "); |
222 |
{ |
|
|
223 |
buf_len = strlen(buf); |
224 |
BUF_ADD(buf,buf_siz,buf_len, "RST "); |
225 |
} |
181 |
|
226 |
|
182 |
if (GET_VALUE(22).b) |
227 |
if (GET_VALUE(22).b) |
183 |
buf_cur += sprintf(buf_cur, "SYN "); |
228 |
{ |
|
|
229 |
buf_len = strlen(buf); |
230 |
BUF_ADD(buf,buf_siz,buf_len, "SYN "); |
231 |
} |
184 |
|
232 |
|
185 |
if (GET_VALUE(23).b) |
233 |
if (GET_VALUE(23).b) |
186 |
buf_cur += sprintf(buf_cur, "FIN "); |
234 |
{ |
|
|
235 |
buf_len = strlen(buf); |
236 |
BUF_ADD(buf,buf_siz,buf_len, "FIN "); |
237 |
} |
187 |
|
238 |
|
188 |
buf_cur += sprintf(buf_cur, "URGP=%u ", GET_VALUE(24).ui16); |
239 |
buf_len = strlen(buf); |
|
|
240 |
BUF_ADD(buf,buf_siz,buf_len, "URGP=%u ", GET_VALUE(24).ui16); |
189 |
|
241 |
|
190 |
break; |
242 |
break; |
191 |
case IPPROTO_UDP: |
243 |
case IPPROTO_UDP: |
192 |
|
244 |
|
193 |
buf_cur += sprintf(buf_cur, "PROTO=UDP "); |
245 |
buf_len = strlen(buf); |
|
|
246 |
BUF_ADD(buf,buf_siz,buf_len, "PROTO=UDP "); |
194 |
|
247 |
|
195 |
buf_cur += sprintf(buf_cur, "SPT=%u DPT=%u LEN=%u ", |
248 |
buf_len = strlen(buf); |
|
|
249 |
BUF_ADD(buf,buf_siz,buf_len, "SPT=%u DPT=%u LEN=%u ", |
196 |
GET_VALUE(25).ui16, GET_VALUE(26).ui16, |
250 |
GET_VALUE(25).ui16, GET_VALUE(26).ui16, |
197 |
GET_VALUE(27).ui16); |
251 |
GET_VALUE(27).ui16); |
198 |
break; |
252 |
break; |
199 |
case IPPROTO_ICMP: |
253 |
case IPPROTO_ICMP: |
200 |
|
254 |
|
201 |
buf_cur += sprintf(buf_cur, "PROTO=ICMP "); |
255 |
buf_len = strlen(buf); |
|
|
256 |
BUF_ADD(buf,buf_siz,buf_len, "PROTO=ICMP "); |
202 |
|
257 |
|
203 |
buf_cur += sprintf(buf_cur, "TYPE=%u CODE=%u ", |
258 |
buf_len = strlen(buf); |
|
|
259 |
BUF_ADD(buf,buf_siz,buf_len, "TYPE=%u CODE=%u ", |
204 |
GET_VALUE(28).ui8, GET_VALUE(29).ui8); |
260 |
GET_VALUE(28).ui8, GET_VALUE(29).ui8); |
205 |
|
261 |
|
206 |
switch (GET_VALUE(28).ui8) { |
262 |
switch (GET_VALUE(28).ui8) { |
207 |
case ICMP_ECHO: |
263 |
case ICMP_ECHO: |
208 |
case ICMP_ECHOREPLY: |
264 |
case ICMP_ECHOREPLY: |
209 |
buf_cur += sprintf(buf_cur, "ID=%u SEQ=%u ", |
265 |
buf_len = strlen(buf); |
|
|
266 |
BUF_ADD(buf,buf_siz,buf_len, "ID=%u SEQ=%u ", |
210 |
GET_VALUE(30).ui16, |
267 |
GET_VALUE(30).ui16, |
211 |
GET_VALUE(31).ui16); |
268 |
GET_VALUE(31).ui16); |
212 |
break; |
269 |
break; |
213 |
case ICMP_PARAMETERPROB: |
270 |
case ICMP_PARAMETERPROB: |
214 |
buf_cur += sprintf(buf_cur, "PARAMETER=%u ", |
271 |
buf_len = strlen(buf); |
|
|
272 |
BUF_ADD(buf,buf_siz,buf_len, "PARAMETER=%u ", |
215 |
GET_VALUE(32).ui32 >> 24); |
273 |
GET_VALUE(32).ui32 >> 24); |
216 |
break; |
274 |
break; |
217 |
case ICMP_REDIRECT: |
275 |
case ICMP_REDIRECT: |
218 |
buf_cur += sprintf(buf_cur, "GATEWAY=%s ", inet_ntoa((struct in_addr) {htonl(GET_VALUE(32).ui32)})); |
276 |
buf_len = strlen(buf); |
|
|
277 |
BUF_ADD(buf,buf_siz,buf_len, "GATEWAY=%s ", inet_ntoa((struct in_addr) {htonl(GET_VALUE(32).ui32)})); |
219 |
break; |
278 |
break; |
220 |
case ICMP_DEST_UNREACH: |
279 |
case ICMP_DEST_UNREACH: |
221 |
if (GET_VALUE(29).ui8 == ICMP_FRAG_NEEDED) |
280 |
if (GET_VALUE(29).ui8 == ICMP_FRAG_NEEDED) |
222 |
buf_cur += sprintf(buf_cur, "MTU=%u ", |
281 |
{ |
|
|
282 |
buf_len = strlen(buf); |
283 |
BUF_ADD(buf,buf_siz,buf_len, "MTU=%u ", |
223 |
GET_VALUE(33).ui16); |
284 |
GET_VALUE(33).ui16); |
|
|
285 |
} |
224 |
break; |
286 |
break; |
225 |
} |
287 |
} |
226 |
break; |
288 |
break; |
227 |
case IPPROTO_ESP: |
289 |
case IPPROTO_ESP: |
228 |
case IPPROTO_AH: |
290 |
case IPPROTO_AH: |
229 |
buf_cur += sprintf(buf_cur, "PROTO=%s ", GET_VALUE(12).ui8 == IPPROTO_ESP ? "ESP" : "AH"); |
291 |
buf_len = strlen(buf); |
|
|
292 |
BUF_ADD(buf,buf_siz,buf_len, "PROTO=%s ", GET_VALUE(12).ui8 == IPPROTO_ESP ? "ESP" : "AH"); |
230 |
/* FIXME: "INCOMPLETE [%u bytes]" in case of short pkt */ |
293 |
/* FIXME: "INCOMPLETE [%u bytes]" in case of short pkt */ |
231 |
if (intr_ids[34].id > 0) { |
294 |
if (intr_ids[34].id > 0) { |
232 |
buf_cur += sprintf(buf_cur, "SPI=0x%x ", GET_VALUE(34).ui32); |
295 |
buf_len = strlen(buf); |
|
|
296 |
BUF_ADD(buf,buf_siz,buf_len, "SPI=0x%x ", GET_VALUE(34).ui32); |
233 |
} |
297 |
} |
234 |
break; |
298 |
break; |
235 |
default: |
299 |
default: |
236 |
|
300 |
|
237 |
buf_cur += sprintf(buf_cur, "PROTO=%u ", GET_VALUE(11).ui8); |
301 |
buf_len = strlen(buf); |
|
|
302 |
BUF_ADD(buf,buf_siz,buf_len, "PROTO=%u ", GET_VALUE(11).ui8); |
238 |
} |
303 |
} |
239 |
strcat(buf_cur, "\n"); |
304 |
buf_len = strlen(buf); |
|
|
305 |
BUF_ADD(buf,buf_siz,buf_len, "\n"); |
306 |
|
307 |
#undef BUF_ADD |
240 |
|
308 |
|
241 |
return 0; |
309 |
return 0; |
242 |
} |
310 |
} |
243 |
-- extensions/printpkt.h |
|
|
Lines 1-7
Link Here
|
1 |
#ifndef _PRINTPKT_H |
1 |
#ifndef _PRINTPKT_H |
2 |
#define _PRINTPKT_H |
2 |
#define _PRINTPKT_H |
3 |
|
3 |
|
4 |
int printpkt_print(ulog_iret_t *res, char *buf, int prefix); |
4 |
int printpkt_print(ulog_iret_t *res, char *buf, size_t buf_siz, int prefix); |
5 |
int printpkt_init(void); |
5 |
int printpkt_init(void); |
6 |
|
6 |
|
7 |
#endif |
7 |
#endif |
8 |
-- extensions/ulogd_BASE.c |
|
|
Lines 65-73
static ulog_iret_t *_interp_raw(ulog_int
Link Here
|
65 |
int i; |
65 |
int i; |
66 |
char *buf, *oldbuf = NULL; |
66 |
char *buf, *oldbuf = NULL; |
67 |
ulog_iret_t *ret = ip->result; |
67 |
ulog_iret_t *ret = ip->result; |
|
|
68 |
size_t siz; |
68 |
|
69 |
|
69 |
if (pkt->mac_len) { |
70 |
if (pkt->mac_len) { |
70 |
buf = (char *) malloc(3 * pkt->mac_len + 1); |
71 |
siz = 3 * pkt->mac_len + 1; |
|
|
72 |
buf = (char *) malloc(siz); |
71 |
if (!buf) { |
73 |
if (!buf) { |
72 |
ulogd_log(ULOGD_ERROR, "OOM!!!\n"); |
74 |
ulogd_log(ULOGD_ERROR, "OOM!!!\n"); |
73 |
return NULL; |
75 |
return NULL; |
Lines 77-83
static ulog_iret_t *_interp_raw(ulog_int
Link Here
|
77 |
p = pkt->mac; |
79 |
p = pkt->mac; |
78 |
oldbuf = buf; |
80 |
oldbuf = buf; |
79 |
for (i = 0; i < pkt->mac_len; i++, p++) |
81 |
for (i = 0; i < pkt->mac_len; i++, p++) |
80 |
sprintf(buf, "%s%02x%c", oldbuf, *p, i==pkt->mac_len-1 ? ' ':':'); |
82 |
snprintf(buf, siz, "%s%02x%c", oldbuf, *p, i==pkt->mac_len-1 ? ' ':':'); |
81 |
ret[0].value.ptr = buf; |
83 |
ret[0].value.ptr = buf; |
82 |
ret[0].flags |= ULOGD_RETF_VALID; |
84 |
ret[0].flags |= ULOGD_RETF_VALID; |
83 |
} |
85 |
} |
84 |
-- extensions/ulogd_LOGEMU.c |
|
|
Lines 67-73
static int _output_logemu(ulog_iret_t *r
Link Here
|
67 |
{ |
67 |
{ |
68 |
static char buf[4096]; |
68 |
static char buf[4096]; |
69 |
|
69 |
|
70 |
printpkt_print(res, buf, 1); |
70 |
printpkt_print(res, buf, sizeof(buf), 1); |
71 |
|
71 |
|
72 |
fprintf(of, "%s", buf); |
72 |
fprintf(of, "%s", buf); |
73 |
|
73 |
|
74 |
-- extensions/ulogd_PWSNIFF.c |
|
|
Lines 116-122
static ulog_iret_t *_interp_pwsniff(ulog
Link Here
|
116 |
return NULL; |
116 |
return NULL; |
117 |
} |
117 |
} |
118 |
strncpy(ret[0].value.ptr, (const char *)begp, len); |
118 |
strncpy(ret[0].value.ptr, (const 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
static ulog_iret_t *_interp_pwsniff(ulog
Link Here
|
126 |
return NULL; |
126 |
return NULL; |
127 |
} |
127 |
} |
128 |
strncpy(ret[1].value.ptr, (const char *)pw_begp, pw_len); |
128 |
strncpy(ret[1].value.ptr, (const 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; |
133 |
-- extensions/ulogd_SYSLOG.c |
|
|
Lines 61-67
static int _output_syslog(ulog_iret_t *r
Link Here
|
61 |
{ |
61 |
{ |
62 |
static char buf[4096]; |
62 |
static char buf[4096]; |
63 |
|
63 |
|
64 |
printpkt_print(res, buf, 0); |
64 |
printpkt_print(res, buf, sizeof(buf), 0); |
65 |
syslog(syslog_level|syslog_facility, buf); |
65 |
syslog(syslog_level|syslog_facility, buf); |
66 |
|
66 |
|
67 |
return 0; |
67 |
return 0; |
68 |
-- mysql/ulogd_MYSQL.c |
|
|
Lines 39-44
Link Here
|
39 |
#include <ulogd/ulogd.h> |
39 |
#include <ulogd/ulogd.h> |
40 |
#include <ulogd/conffile.h> |
40 |
#include <ulogd/conffile.h> |
41 |
#include <mysql/mysql.h> |
41 |
#include <mysql/mysql.h> |
|
|
42 |
#include <inttypes.h> |
42 |
|
43 |
|
43 |
#ifdef DEBUG_MYSQL |
44 |
#ifdef DEBUG_MYSQL |
44 |
#define DEBUGP(x, args...) fprintf(stderr, x, ## args) |
45 |
#define DEBUGP(x, args...) fprintf(stderr, x, ## args) |
Lines 61-66
static struct _field *fields;
Link Here
|
61 |
/* buffer for our insert statement */ |
62 |
/* buffer for our insert statement */ |
62 |
static char *stmt; |
63 |
static char *stmt; |
63 |
|
64 |
|
|
|
65 |
/* size of our insert statement buffer */ |
66 |
static size_t stmt_siz; |
67 |
|
64 |
/* pointer to the beginning of the "VALUES" part */ |
68 |
/* pointer to the beginning of the "VALUES" part */ |
65 |
static char *stmt_val; |
69 |
static char *stmt_val; |
66 |
|
70 |
|
Lines 130-200
static int mysql_output(ulog_iret_t *res
Link Here
|
130 |
|
134 |
|
131 |
if (!res || !IS_VALID((*res))) { |
135 |
if (!res || !IS_VALID((*res))) { |
132 |
/* no result, we have to fake something */ |
136 |
/* no result, we have to fake something */ |
133 |
sprintf(stmt_ins, "NULL,"); |
137 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "NULL,"); |
134 |
stmt_ins = stmt + strlen(stmt); |
138 |
stmt_ins = stmt + strlen(stmt); |
135 |
continue; |
139 |
continue; |
136 |
} |
140 |
} |
137 |
|
141 |
|
138 |
switch (res->type) { |
142 |
switch (res->type) { |
139 |
case ULOGD_RET_INT8: |
143 |
case ULOGD_RET_INT8: |
140 |
sprintf(stmt_ins, "%d,", res->value.i8); |
144 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%d,", res->value.i8); |
141 |
break; |
145 |
break; |
142 |
case ULOGD_RET_INT16: |
146 |
case ULOGD_RET_INT16: |
143 |
sprintf(stmt_ins, "%d,", res->value.i16); |
147 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%d,", res->value.i16); |
144 |
break; |
148 |
break; |
145 |
case ULOGD_RET_INT32: |
149 |
case ULOGD_RET_INT32: |
146 |
sprintf(stmt_ins, "%d,", res->value.i32); |
150 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%d,", res->value.i32); |
147 |
break; |
151 |
break; |
148 |
case ULOGD_RET_INT64: |
152 |
case ULOGD_RET_INT64: |
149 |
sprintf(stmt_ins, "%lld,", res->value.i64); |
153 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%"PRId64",", res->value.i64); |
150 |
break; |
154 |
break; |
151 |
case ULOGD_RET_UINT8: |
155 |
case ULOGD_RET_UINT8: |
152 |
sprintf(stmt_ins, "%u,", res->value.ui8); |
156 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%u,", res->value.ui8); |
153 |
break; |
157 |
break; |
154 |
case ULOGD_RET_UINT16: |
158 |
case ULOGD_RET_UINT16: |
155 |
sprintf(stmt_ins, "%u,", res->value.ui16); |
159 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%u,", res->value.ui16); |
156 |
break; |
160 |
break; |
157 |
case ULOGD_RET_IPADDR: |
161 |
case ULOGD_RET_IPADDR: |
158 |
#ifdef IP_AS_STRING |
162 |
#ifdef IP_AS_STRING |
159 |
memset(&addr, 0, sizeof(addr)); |
163 |
memset(&addr, 0, sizeof(addr)); |
160 |
addr.s_addr = ntohl(res->value.ui32); |
164 |
addr.s_addr = ntohl(res->value.ui32); |
161 |
*stmt_ins++ = '\''; |
|
|
162 |
tmpstr = inet_ntoa(addr); |
165 |
tmpstr = inet_ntoa(addr); |
|
|
166 |
if(stmt_siz > (stmt_ins-stmt)+(strlen(tmpstr)*2)+4) |
167 |
{ |
168 |
*stmt_ins++ = '\''; |
163 |
#ifdef OLD_MYSQL |
169 |
#ifdef OLD_MYSQL |
164 |
mysql_escape_string(stmt_ins, tmpstr, |
170 |
mysql_escape_string(stmt_ins, tmpstr, |
165 |
strlen(tmpstr)); |
171 |
strlen(tmpstr)); |
166 |
#else |
172 |
#else |
167 |
mysql_real_escape_string(dbh, stmt_ins, |
173 |
mysql_real_escape_string(dbh, stmt_ins, |
168 |
tmpstr, |
174 |
tmpstr, |
169 |
strlen(tmpstr)); |
175 |
strlen(tmpstr)); |
170 |
#endif /* OLD_MYSQL */ |
176 |
#endif /* OLD_MYSQL */ |
171 |
stmt_ins = stmt + strlen(stmt); |
177 |
stmt_ins = stmt + strlen(stmt); |
172 |
sprintf(stmt_ins, "',"); |
178 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "',"); |
|
|
179 |
} |
180 |
else |
181 |
{ |
182 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "'',"); |
183 |
} |
173 |
break; |
184 |
break; |
174 |
#endif /* IP_AS_STRING */ |
185 |
#endif /* IP_AS_STRING */ |
175 |
/* EVIL: fallthrough when logging IP as |
186 |
/* EVIL: fallthrough when logging IP as |
176 |
* u_int32_t */ |
187 |
* u_int32_t */ |
177 |
case ULOGD_RET_UINT32: |
188 |
case ULOGD_RET_UINT32: |
178 |
sprintf(stmt_ins, "%u,", res->value.ui32); |
189 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%u,", res->value.ui32); |
179 |
break; |
190 |
break; |
180 |
case ULOGD_RET_UINT64: |
191 |
case ULOGD_RET_UINT64: |
181 |
sprintf(stmt_ins, "%llu,", res->value.ui64); |
192 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%"PRIu64",", res->value.ui64); |
182 |
break; |
193 |
break; |
183 |
case ULOGD_RET_BOOL: |
194 |
case ULOGD_RET_BOOL: |
184 |
sprintf(stmt_ins, "'%d',", res->value.b); |
195 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "'%d',", res->value.b); |
185 |
break; |
196 |
break; |
186 |
case ULOGD_RET_STRING: |
197 |
case ULOGD_RET_STRING: |
187 |
*stmt_ins++ = '\''; |
198 |
if(stmt_siz > (stmt_ins-stmt)+(strlen(res->value.ptr)*2)+4) |
|
|
199 |
{ |
200 |
*stmt_ins++ = '\''; |
188 |
#ifdef OLD_MYSQL |
201 |
#ifdef OLD_MYSQL |
189 |
mysql_escape_string(stmt_ins, res->value.ptr, |
202 |
mysql_escape_string(stmt_ins, res->value.ptr, |
190 |
strlen(res->value.ptr)); |
203 |
strlen(res->value.ptr)); |
191 |
#else |
204 |
#else |
192 |
mysql_real_escape_string(dbh, stmt_ins, |
205 |
mysql_real_escape_string(dbh, stmt_ins, |
193 |
res->value.ptr, strlen(res->value.ptr)); |
206 |
res->value.ptr, strlen(res->value.ptr)); |
194 |
#endif |
207 |
#endif |
195 |
stmt_ins = stmt + strlen(stmt); |
208 |
stmt_ins = stmt + strlen(stmt); |
196 |
sprintf(stmt_ins, "',"); |
209 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "',"); |
197 |
/* sprintf(stmt_ins, "'%s',", res->value.ptr); */ |
210 |
} |
|
|
211 |
else |
212 |
{ |
213 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "'',"); |
214 |
} |
215 |
/* snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "'%s',", res->value.ptr); */ |
198 |
break; |
216 |
break; |
199 |
case ULOGD_RET_RAW: |
217 |
case ULOGD_RET_RAW: |
200 |
ulogd_log(ULOGD_NOTICE, |
218 |
ulogd_log(ULOGD_NOTICE, |
Lines 230-236
static int mysql_output(ulog_iret_t *res
Link Here
|
230 |
static int mysql_createstmt(void) |
248 |
static int mysql_createstmt(void) |
231 |
{ |
249 |
{ |
232 |
struct _field *f; |
250 |
struct _field *f; |
233 |
unsigned int size; |
251 |
size_t size; |
234 |
char buf[ULOGD_MAX_KEYLEN]; |
252 |
char buf[ULOGD_MAX_KEYLEN]; |
235 |
char *underscore; |
253 |
char *underscore; |
236 |
|
254 |
|
Lines 241-247
static int mysql_createstmt(void)
Link Here
|
241 |
} |
259 |
} |
242 |
|
260 |
|
243 |
/* caclulate the size for the insert statement */ |
261 |
/* caclulate the size for the insert statement */ |
244 |
size = strlen(MYSQL_INSERTTEMPL) + strlen(table_ce.u.string); |
262 |
size = strlen(MYSQL_INSERTTEMPL) + strlen(table_ce.u.string) + 1; |
245 |
|
263 |
|
246 |
for (f = fields; f; f = f->next) { |
264 |
for (f = fields; f; f = f->next) { |
247 |
/* we need space for the key and a comma, as well as |
265 |
/* we need space for the key and a comma, as well as |
Lines 252-276
static int mysql_createstmt(void)
Link Here
|
252 |
ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", size); |
270 |
ulogd_log(ULOGD_DEBUG, "allocating %u bytes for statement\n", size); |
253 |
|
271 |
|
254 |
stmt = (char *) malloc(size); |
272 |
stmt = (char *) malloc(size); |
255 |
|
|
|
256 |
if (!stmt) { |
273 |
if (!stmt) { |
257 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
274 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
258 |
return 1; |
275 |
return 1; |
259 |
} |
276 |
} |
|
|
277 |
stmt_siz = size; |
260 |
|
278 |
|
261 |
sprintf(stmt, "insert into %s (", table_ce.u.string); |
279 |
snprintf(stmt, stmt_siz, "insert into %s (", table_ce.u.string); |
262 |
stmt_val = stmt + strlen(stmt); |
280 |
stmt_val = stmt + strlen(stmt); |
263 |
|
281 |
|
264 |
for (f = fields; f; f = f->next) { |
282 |
for (f = fields; f; f = f->next) { |
265 |
strncpy(buf, f->name, ULOGD_MAX_KEYLEN); |
283 |
strncpy(buf, f->name, ULOGD_MAX_KEYLEN-1); |
|
|
284 |
buf[ULOGD_MAX_KEYLEN-1] = '\0'; |
266 |
while ((underscore = strchr(buf, '.'))) |
285 |
while ((underscore = strchr(buf, '.'))) |
267 |
*underscore = '_'; |
286 |
*underscore = '_'; |
268 |
sprintf(stmt_val, "%s,", buf); |
287 |
snprintf(stmt_val, stmt_siz-(stmt_val-stmt), "%s,", buf); |
269 |
stmt_val = stmt + strlen(stmt); |
288 |
stmt_val = stmt + strlen(stmt); |
270 |
} |
289 |
} |
271 |
*(stmt_val - 1) = ')'; |
290 |
*(stmt_val - 1) = ')'; |
272 |
|
291 |
|
273 |
sprintf(stmt_val, " values ("); |
292 |
snprintf(stmt_val, stmt_siz-(stmt_val-stmt), " values ("); |
274 |
stmt_val = stmt + strlen(stmt); |
293 |
stmt_val = stmt + strlen(stmt); |
275 |
|
294 |
|
276 |
ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); |
295 |
ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); |
Lines 298-304
static int mysql_get_columns(const char
Link Here
|
298 |
while ((field = mysql_fetch_field(result))) { |
317 |
while ((field = mysql_fetch_field(result))) { |
299 |
|
318 |
|
300 |
/* replace all underscores with dots */ |
319 |
/* replace all underscores with dots */ |
301 |
strncpy(buf, field->name, ULOGD_MAX_KEYLEN); |
320 |
strncpy(buf, field->name, ULOGD_MAX_KEYLEN-1); |
|
|
321 |
buf[ULOGD_MAX_KEYLEN-1] = '\0'; |
302 |
while ((underscore = strchr(buf, '_'))) |
322 |
while ((underscore = strchr(buf, '_'))) |
303 |
*underscore = '.'; |
323 |
*underscore = '.'; |
304 |
|
324 |
|
Lines 317-323
static int mysql_get_columns(const char
Link Here
|
317 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
337 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
318 |
return 1; |
338 |
return 1; |
319 |
} |
339 |
} |
320 |
strncpy(f->name, buf, ULOGD_MAX_KEYLEN); |
340 |
strncpy(f->name, buf, ULOGD_MAX_KEYLEN-1); |
|
|
341 |
f->name[ULOGD_MAX_KEYLEN-1] = '\0'; |
321 |
f->id = id; |
342 |
f->id = id; |
322 |
f->next = fields; |
343 |
f->next = fields; |
323 |
fields = f; |
344 |
fields = f; |
324 |
-- pgsql/ulogd_PGSQL.c |
|
|
Lines 39-44
static struct _field *fields;
Link Here
|
39 |
/* buffer for our insert statement */ |
39 |
/* buffer for our insert statement */ |
40 |
static char *stmt; |
40 |
static char *stmt; |
41 |
|
41 |
|
|
|
42 |
/* size of our insert statement buffer */ |
43 |
static size_t stmt_siz; |
44 |
|
42 |
/* pointer to the beginning of the "VALUES" part */ |
45 |
/* pointer to the beginning of the "VALUES" part */ |
43 |
static char *stmt_val; |
46 |
static char *stmt_val; |
44 |
|
47 |
|
Lines 120-181
static int pgsql_output(ulog_iret_t *res
Link Here
|
120 |
|
123 |
|
121 |
if (!res || !IS_VALID((*res))) { |
124 |
if (!res || !IS_VALID((*res))) { |
122 |
/* no result, we have to fake something */ |
125 |
/* no result, we have to fake something */ |
123 |
sprintf(stmt_ins, "NULL,"); |
126 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "NULL,"); |
124 |
stmt_ins = stmt + strlen(stmt); |
127 |
stmt_ins = stmt + strlen(stmt); |
125 |
continue; |
128 |
continue; |
126 |
} |
129 |
} |
127 |
|
130 |
|
128 |
switch (res->type) { |
131 |
switch (res->type) { |
129 |
case ULOGD_RET_INT8: |
132 |
case ULOGD_RET_INT8: |
130 |
sprintf(stmt_ins, "%d,", res->value.i8); |
133 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%d,", res->value.i8); |
131 |
break; |
134 |
break; |
132 |
case ULOGD_RET_INT16: |
135 |
case ULOGD_RET_INT16: |
133 |
sprintf(stmt_ins, "%d,", res->value.i16); |
136 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%d,", res->value.i16); |
134 |
break; |
137 |
break; |
135 |
case ULOGD_RET_INT32: |
138 |
case ULOGD_RET_INT32: |
136 |
sprintf(stmt_ins, "%d,", res->value.i32); |
139 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%d,", res->value.i32); |
137 |
break; |
140 |
break; |
138 |
case ULOGD_RET_INT64: |
141 |
case ULOGD_RET_INT64: |
139 |
sprintf(stmt_ins, "%lld,", res->value.i64); |
142 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%lld,", res->value.i64); |
140 |
break; |
143 |
break; |
141 |
case ULOGD_RET_UINT8: |
144 |
case ULOGD_RET_UINT8: |
142 |
sprintf(stmt_ins, "%u,", res->value.ui8); |
145 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%u,", res->value.ui8); |
143 |
break; |
146 |
break; |
144 |
case ULOGD_RET_UINT16: |
147 |
case ULOGD_RET_UINT16: |
145 |
sprintf(stmt_ins, "%u,", res->value.ui16); |
148 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%u,", res->value.ui16); |
146 |
break; |
149 |
break; |
147 |
case ULOGD_RET_IPADDR: |
150 |
case ULOGD_RET_IPADDR: |
148 |
#ifdef IP_AS_STRING |
151 |
#ifdef IP_AS_STRING |
149 |
*stmt_ins++ = '\''; |
|
|
150 |
memset(&addr, 0, sizeof(addr)); |
152 |
memset(&addr, 0, sizeof(addr)); |
151 |
addr.s_addr = ntohl(res->value.ui32); |
153 |
addr.s_addr = ntohl(res->value.ui32); |
152 |
tmpstr = (char *)inet_ntoa(addr); |
154 |
tmpstr = (char *)inet_ntoa(addr); |
153 |
PQescapeString(stmt_ins,tmpstr,strlen(tmpstr)); |
155 |
if(stmt_siz > (stmt_ins-stmt)+(strlen(tmpstr)*2)+4) |
154 |
stmt_ins = stmt + strlen(stmt); |
156 |
{ |
155 |
sprintf(stmt_ins, "',"); |
157 |
*stmt_ins++ = '\''; |
|
|
158 |
PQescapeString(stmt_ins,tmpstr,strlen(tmpstr)); |
159 |
stmt_ins = stmt + strlen(stmt); |
160 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "',"); |
161 |
} |
162 |
else |
163 |
{ |
164 |
ulogd_log(ULOGD_NOTICE,"%s: pgsql - no space to add escaped ip string to insert statement\n"); |
165 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "'',"); |
166 |
} |
156 |
break; |
167 |
break; |
157 |
#endif /* IP_AS_STRING */ |
168 |
#endif /* IP_AS_STRING */ |
158 |
/* EVIL: fallthrough when logging IP as |
169 |
/* EVIL: fallthrough when logging IP as |
159 |
* u_int32_t */ |
170 |
* u_int32_t */ |
160 |
|
171 |
|
161 |
case ULOGD_RET_UINT32: |
172 |
case ULOGD_RET_UINT32: |
162 |
sprintf(stmt_ins, "%u,", res->value.ui32); |
173 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%u,", res->value.ui32); |
163 |
break; |
174 |
break; |
164 |
case ULOGD_RET_UINT64: |
175 |
case ULOGD_RET_UINT64: |
165 |
sprintf(stmt_ins, "%llu,", res->value.ui64); |
176 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "%llu,", res->value.ui64); |
166 |
break; |
177 |
break; |
167 |
case ULOGD_RET_BOOL: |
178 |
case ULOGD_RET_BOOL: |
168 |
sprintf(stmt_ins, "'%d',", res->value.b); |
179 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "'%d',", res->value.b); |
169 |
break; |
180 |
break; |
170 |
case ULOGD_RET_STRING: |
181 |
case ULOGD_RET_STRING: |
171 |
*stmt_ins++ = '\''; |
182 |
if(stmt_siz > (stmt_ins-stmt)+(strlen(res->value.ptr)*2)+4) |
172 |
PQescapeString(stmt_ins,res->value.ptr,strlen(res->value.ptr)); |
183 |
{ |
173 |
stmt_ins = stmt + strlen(stmt); |
184 |
*stmt_ins++ = '\''; |
174 |
sprintf(stmt_ins, "',"); |
185 |
PQescapeString(stmt_ins,res->value.ptr,strlen(res->value.ptr)); |
|
|
186 |
stmt_ins = stmt + strlen(stmt); |
187 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "',"); |
188 |
} |
189 |
else |
190 |
{ |
191 |
ulogd_log(ULOGD_NOTICE,"%s: pgsql - no space to add escaped string to insert statement\n"); |
192 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "'',"); |
193 |
} |
175 |
break; |
194 |
break; |
176 |
case ULOGD_RET_RAW: |
195 |
case ULOGD_RET_RAW: |
177 |
ulogd_log(ULOGD_NOTICE,"%s: pgsql doesn't support type RAW\n",res->key); |
196 |
ulogd_log(ULOGD_NOTICE,"%s: pgsql doesn't support type RAW\n",res->key); |
178 |
sprintf(stmt_ins, "NULL,"); |
197 |
snprintf(stmt_ins, stmt_siz-(stmt_ins-stmt), "NULL,"); |
179 |
break; |
198 |
break; |
180 |
default: |
199 |
default: |
181 |
ulogd_log(ULOGD_NOTICE, |
200 |
ulogd_log(ULOGD_NOTICE, |
Lines 205-216
static int pgsql_output(ulog_iret_t *res
Link Here
|
205 |
/* Determine if server support schemas */ |
224 |
/* Determine if server support schemas */ |
206 |
static int pgsql_namespace(void) { |
225 |
static int pgsql_namespace(void) { |
207 |
PGresult *result; |
226 |
PGresult *result; |
208 |
char pgbuf[strlen(PGSQL_HAVE_NAMESPACE_TEMPLATE)+strlen(schema_ce.u.string)+1]; |
227 |
size_t pgbuf_siz = strlen(PGSQL_HAVE_NAMESPACE_TEMPLATE)+strlen(schema_ce.u.string)+1; |
|
|
228 |
char pgbuf[pgbuf_siz]; |
209 |
|
229 |
|
210 |
if (!dbh) |
230 |
if (!dbh) |
211 |
return 1; |
231 |
return 1; |
212 |
|
232 |
|
213 |
sprintf(pgbuf, PGSQL_HAVE_NAMESPACE_TEMPLATE, schema_ce.u.string); |
233 |
snprintf(pgbuf, pgbuf_siz, PGSQL_HAVE_NAMESPACE_TEMPLATE, schema_ce.u.string); |
214 |
ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf); |
234 |
ulogd_log(ULOGD_DEBUG, "%s\n", pgbuf); |
215 |
|
235 |
|
216 |
result = PQexec(dbh, pgbuf); |
236 |
result = PQexec(dbh, pgbuf); |
Lines 265-289
static int pgsql_createstmt(void)
Link Here
|
265 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
285 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
266 |
return 1; |
286 |
return 1; |
267 |
} |
287 |
} |
|
|
288 |
stmt_siz = size; |
268 |
|
289 |
|
269 |
if (pgsql_have_schemas) { |
290 |
if (pgsql_have_schemas) { |
270 |
sprintf(stmt, "insert into %s.%s (", schema_ce.u.string, table_ce.u.string); |
291 |
snprintf(stmt, stmt_siz, "insert into %s.%s (", schema_ce.u.string, table_ce.u.string); |
271 |
} else { |
292 |
} else { |
272 |
sprintf(stmt, "insert into %s (", table_ce.u.string); |
293 |
snprintf(stmt, stmt_siz, "insert into %s (", table_ce.u.string); |
273 |
} |
294 |
} |
274 |
|
295 |
|
275 |
stmt_val = stmt + strlen(stmt); |
296 |
stmt_val = stmt + strlen(stmt); |
276 |
|
297 |
|
277 |
for (f = fields; f; f = f->next) { |
298 |
for (f = fields; f; f = f->next) { |
278 |
strncpy(buf, f->name, ULOGD_MAX_KEYLEN); |
299 |
strncpy(buf, f->name, ULOGD_MAX_KEYLEN-1); |
|
|
300 |
buf[ULOGD_MAX_KEYLEN-1] = '\0'; |
279 |
while ((underscore = strchr(buf, '.'))) |
301 |
while ((underscore = strchr(buf, '.'))) |
280 |
*underscore = '_'; |
302 |
*underscore = '_'; |
281 |
sprintf(stmt_val, "%s,", buf); |
303 |
snprintf(stmt_val, stmt_siz-(stmt_val-stmt), "%s,", buf); |
282 |
stmt_val = stmt + strlen(stmt); |
304 |
stmt_val = stmt + strlen(stmt); |
283 |
} |
305 |
} |
284 |
*(stmt_val - 1) = ')'; |
306 |
*(stmt_val - 1) = ')'; |
285 |
|
307 |
|
286 |
sprintf(stmt_val, " values ("); |
308 |
snprintf(stmt_val, stmt_siz-(stmt_val-stmt), " values ("); |
287 |
stmt_val = stmt + strlen(stmt); |
309 |
stmt_val = stmt + strlen(stmt); |
288 |
|
310 |
|
289 |
ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); |
311 |
ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); |
Lines 331-337
static int pgsql_get_columns(const char
Link Here
|
331 |
for (intaux=0; intaux<PQntuples(result); intaux++) { |
353 |
for (intaux=0; intaux<PQntuples(result); intaux++) { |
332 |
|
354 |
|
333 |
/* replace all underscores with dots */ |
355 |
/* replace all underscores with dots */ |
334 |
strncpy(buf, PQgetvalue(result, intaux, 0), ULOGD_MAX_KEYLEN); |
356 |
strncpy(buf, PQgetvalue(result, intaux, 0), ULOGD_MAX_KEYLEN-1); |
|
|
357 |
buf[ULOGD_MAX_KEYLEN-1] = '\0'; |
335 |
while ((underscore = strchr(buf, '_'))) |
358 |
while ((underscore = strchr(buf, '_'))) |
336 |
*underscore = '.'; |
359 |
*underscore = '.'; |
337 |
|
360 |
|
Lines 350-356
static int pgsql_get_columns(const char
Link Here
|
350 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
373 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
351 |
return 1; |
374 |
return 1; |
352 |
} |
375 |
} |
353 |
strncpy(f->name, buf, ULOGD_MAX_KEYLEN); |
376 |
strncpy(f->name, buf, ULOGD_MAX_KEYLEN-1); |
|
|
377 |
f->name[ULOGD_MAX_KEYLEN-1] = '\0'; |
354 |
f->id = id; |
378 |
f->id = id; |
355 |
f->next = fields; |
379 |
f->next = fields; |
356 |
fields = f; |
380 |
fields = f; |
Lines 384-415
static int pgsql_open_db(char *server, i
Link Here
|
384 |
if (port) |
408 |
if (port) |
385 |
len += 20; |
409 |
len += 20; |
386 |
|
410 |
|
387 |
connstr = (char *) malloc(len); |
411 |
connstr = (char *) malloc(len+1); |
388 |
if (!connstr) |
412 |
if (!connstr) |
389 |
return 1; |
413 |
return 1; |
390 |
|
414 |
|
391 |
if (server) { |
415 |
if (server) { |
392 |
strcpy(connstr, " host="); |
416 |
strncpy(connstr, " host=", len); |
393 |
strcat(connstr, server); |
417 |
connstr[len] = '\0'; |
|
|
418 |
strncat(connstr, server, len-strlen(connstr)); |
394 |
} |
419 |
} |
395 |
|
420 |
|
396 |
if (port) { |
421 |
if (port) { |
397 |
char portbuf[20]; |
422 |
char portbuf[20]; |
398 |
snprintf(portbuf, sizeof(portbuf), " port=%u", port); |
423 |
snprintf(portbuf, sizeof(portbuf), " port=%u", port); |
399 |
strcat(connstr, portbuf); |
424 |
strncat(connstr, portbuf, len-strlen(connstr)); |
400 |
} |
425 |
} |
401 |
|
426 |
|
402 |
strcat(connstr, " dbname="); |
427 |
strncat(connstr, " dbname=", len-strlen(connstr)); |
403 |
strcat(connstr, db); |
428 |
strncat(connstr, db, len-strlen(connstr)); |
404 |
strcat(connstr, " user="); |
429 |
strncat(connstr, " user=", len-strlen(connstr)); |
405 |
strcat(connstr, user); |
430 |
strncat(connstr, user, len-strlen(connstr)); |
406 |
|
431 |
|
407 |
if (pass) { |
432 |
if (pass) { |
408 |
strcat(connstr, " password="); |
433 |
strncat(connstr, " password=", len-strlen(connstr)); |
409 |
strcat(connstr, pass); |
434 |
strncat(connstr, pass, len-strlen(connstr)); |
410 |
} |
435 |
} |
411 |
|
436 |
|
412 |
dbh = PQconnectdb(connstr); |
437 |
dbh = PQconnectdb(connstr); |
|
|
438 |
free(connstr); |
413 |
if (PQstatus(dbh)!=CONNECTION_OK) { |
439 |
if (PQstatus(dbh)!=CONNECTION_OK) { |
414 |
exit_nicely(dbh); |
440 |
exit_nicely(dbh); |
415 |
return 1; |
441 |
return 1; |
416 |
-- sqlite3/ulogd_SQLITE3.c |
|
|
Lines 55-60
static struct _field *fields;
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 193-199
static int _sqlite3_output(ulog_iret_t *
Link Here
|
193 |
static int _sqlite3_createstmt(void) |
196 |
static int _sqlite3_createstmt(void) |
194 |
{ |
197 |
{ |
195 |
struct _field *f; |
198 |
struct _field *f; |
196 |
unsigned int size; |
199 |
size_t size; |
197 |
char buf[ULOGD_MAX_KEYLEN]; |
200 |
char buf[ULOGD_MAX_KEYLEN]; |
198 |
char *underscore; |
201 |
char *underscore; |
199 |
char *stmt_pos; |
202 |
char *stmt_pos; |
Lines 207-213
static int _sqlite3_createstmt(void)
Link Here
|
207 |
} |
210 |
} |
208 |
|
211 |
|
209 |
/* caclulate the size for the insert statement */ |
212 |
/* caclulate the size for the insert statement */ |
210 |
size = strlen(_SQLITE3_INSERTTEMPL) + strlen(table_ce.u.string); |
213 |
size = strlen(_SQLITE3_INSERTTEMPL) + strlen(table_ce.u.string) + 1; |
211 |
|
214 |
|
212 |
DEBUGP("initial size: %u\n", size); |
215 |
DEBUGP("initial size: %u\n", size); |
213 |
|
216 |
|
Lines 230-258
static int _sqlite3_createstmt(void)
Link Here
|
230 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
233 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
231 |
return 1; |
234 |
return 1; |
232 |
} |
235 |
} |
|
|
236 |
stmt_siz = size; |
233 |
|
237 |
|
234 |
sprintf(stmt, "insert into %s (", table_ce.u.string); |
238 |
snprintf(stmt, stmt_siz, "insert into %s (", table_ce.u.string); |
235 |
stmt_pos = stmt + strlen(stmt); |
239 |
stmt_pos = stmt + strlen(stmt); |
236 |
|
240 |
|
237 |
for (f = fields; f; f = f->next) { |
241 |
for (f = fields; f; f = f->next) { |
238 |
strncpy(buf, f->name, ULOGD_MAX_KEYLEN); |
242 |
strncpy(buf, f->name, ULOGD_MAX_KEYLEN-1); |
|
|
243 |
buf[ULOGD_MAX_KEYLEN-1] = '\0'; |
239 |
while ((underscore = strchr(buf, '.'))) |
244 |
while ((underscore = strchr(buf, '.'))) |
240 |
*underscore = '_'; |
245 |
*underscore = '_'; |
241 |
sprintf(stmt_pos, "%s,", buf); |
246 |
snprintf(stmt_pos, stmt_siz-(stmt_pos-stmt), "%s,", buf); |
242 |
stmt_pos = stmt + strlen(stmt); |
247 |
stmt_pos = stmt + strlen(stmt); |
243 |
} |
248 |
} |
244 |
|
249 |
|
245 |
*(stmt_pos - 1) = ')'; |
250 |
*(stmt_pos - 1) = ')'; |
246 |
|
251 |
|
247 |
sprintf(stmt_pos, " values ("); |
252 |
snprintf(stmt_pos, stmt_siz-(stmt_pos-stmt), " values ("); |
248 |
stmt_pos = stmt + strlen(stmt); |
253 |
stmt_pos = stmt + strlen(stmt); |
249 |
|
254 |
|
250 |
for (i = 0; i < col_count - 1; i++) { |
255 |
for (i = 0; i < col_count - 1; i++) { |
251 |
sprintf(stmt_pos,"?,"); |
256 |
snprintf(stmt_pos, stmt_siz-(stmt_pos-stmt), "?,"); |
252 |
stmt_pos += 2; |
257 |
stmt_pos += 2; |
253 |
} |
258 |
} |
254 |
|
259 |
|
255 |
sprintf(stmt_pos, "?)"); |
260 |
snprintf(stmt_pos, stmt_siz-(stmt_pos-stmt), "?)"); |
256 |
ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); |
261 |
ulogd_log(ULOGD_DEBUG, "stmt='%s'\n", stmt); |
257 |
|
262 |
|
258 |
DEBUGP("about to prepare statement.\n"); |
263 |
DEBUGP("about to prepare statement.\n"); |
Lines 277-283
static int _sqlite3_createstmt(void)
Link Here
|
277 |
static int _sqlite3_get_columns(const char *table) |
282 |
static int _sqlite3_get_columns(const char *table) |
278 |
{ |
283 |
{ |
279 |
char buf[ULOGD_MAX_KEYLEN]; |
284 |
char buf[ULOGD_MAX_KEYLEN]; |
280 |
char query[SQLITE_SELECT_LEN + CONFIG_VAL_STRING_LEN] = "select * from \0"; |
285 |
char query[SQLITE_SELECT_LEN + CONFIG_VAL_STRING_LEN + 1] = "select * from \0"; |
281 |
char *underscore; |
286 |
char *underscore; |
282 |
struct _field *f; |
287 |
struct _field *f; |
283 |
sqlite3_stmt *schema_stmt; |
288 |
sqlite3_stmt *schema_stmt; |
Lines 288-295
static int _sqlite3_get_columns(const ch
Link Here
|
288 |
if (!dbh) |
293 |
if (!dbh) |
289 |
return 1; |
294 |
return 1; |
290 |
|
295 |
|
291 |
strncat(query,table,LINE_LEN); |
296 |
strncat(query,table,sizeof(query)-strlen(query)-1); |
292 |
|
297 |
|
293 |
result = sqlite3_prepare(dbh,query,-1,&schema_stmt,0); |
298 |
result = sqlite3_prepare(dbh,query,-1,&schema_stmt,0); |
294 |
|
299 |
|
295 |
if (result != SQLITE_OK) |
300 |
if (result != SQLITE_OK) |
Lines 297-303
static int _sqlite3_get_columns(const ch
Link Here
|
297 |
|
302 |
|
298 |
for (column = 0; column < sqlite3_column_count(schema_stmt); column++) { |
303 |
for (column = 0; column < sqlite3_column_count(schema_stmt); column++) { |
299 |
/* replace all underscores with dots */ |
304 |
/* replace all underscores with dots */ |
300 |
strncpy(buf, sqlite3_column_name(schema_stmt,column), ULOGD_MAX_KEYLEN); |
305 |
strncpy(buf, sqlite3_column_name(schema_stmt,column), ULOGD_MAX_KEYLEN-1); |
|
|
306 |
buf[ULOGD_MAX_KEYLEN-1] = '\0'; |
301 |
while ((underscore = strchr(buf, '_'))) |
307 |
while ((underscore = strchr(buf, '_'))) |
302 |
*underscore = '.'; |
308 |
*underscore = '.'; |
303 |
|
309 |
|
Lines 316-322
static int _sqlite3_get_columns(const ch
Link Here
|
316 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
322 |
ulogd_log(ULOGD_ERROR, "OOM!\n"); |
317 |
return 1; |
323 |
return 1; |
318 |
} |
324 |
} |
319 |
strncpy(f->name, buf, ULOGD_MAX_KEYLEN); |
325 |
strncpy(f->name, buf, ULOGD_MAX_KEYLEN-1); |
|
|
326 |
f->name[ULOGD_MAX_KEYLEN-1] = '\0'; |
320 |
f->id = id; |
327 |
f->id = id; |
321 |
f->next = fields; |
328 |
f->next = fields; |
322 |
fields = f; |
329 |
fields = f; |