summaryrefslogtreecommitdiff
path: root/openwrt/package/dsniff/patches/gdbm.patch
blob: 2d9256aaef0e1e055f5e60c15ee126c9ad5399d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
diff -Nur dsniff-2.3/configure dsniff-2.3.patched/configure
--- dsniff-2.3/configure	2005-06-09 15:21:49.000000000 +0200
+++ dsniff-2.3.patched/configure	2005-06-09 15:26:41.000000000 +0200
@@ -3051,7 +3051,40 @@
 
 fi
 
+echo $ac_n "checking for libgdbm""... $ac_c" 1>&6
+echo "configure:3059: checking for libgdbm" >&5
+# Check whether --with-gdbm or --without-gdbm was given.
+if test "${with_gdbm+set}" = set; then
+  withval="$with_gdbm"
+   case "$withval" in
+  yes|no)
+     echo "$ac_t""no" 1>&6
+     ;;
+  *)
+     echo "$ac_t""$withval" 1>&6
+     if test -f $withval/include/gdbm.h -a -f $withval/lib/libgdbm.a; then
+        owd=`pwd`
+        if cd $withval; then withval=`pwd`; cd $owd; fi
+	DBINC="-I$withval/include"
+	DBLIB="-L$withval/lib -lgdbm"
+     else
+        { echo "configure: error: gdbm.h or libgdbm.a not found in $withval" 1>&2; exit 1; }
+     fi
+     ;;
+  esac 
+else
+   if test -f ${prefix}/include/gdbm.h; then
+     LNETINC="-I${prefix}/include"
+     LNETLIB="-L${prefix}/lib -lgdbm"
+  elif test -f /usr/include/gdbm.h; then
+     LNETLIB="-lgdbm"
+  else
+     echo "$ac_t""no" 1>&6
+     { echo "configure: error: libgdbm not found" 1>&2; exit 1; }
+  fi
+  echo "$ac_t""yes" 1>&6 
 
+fi
 
 
 echo $ac_n "checking for libnet""... $ac_c" 1>&6
diff -Nur dsniff-2.3/configure dsniff-2.3.patched/configure
--- dsniff-2.3/configure	2005-06-09 15:17:11.000000000 +0200
+++ dsniff-2.3.patched/configure	2005-06-09 14:47:24.000000000 +0200
@@ -16,6 +16,8 @@
 ac_help="$ac_help
   --with-db=DIR           use Berkeley DB (with --enable-compat185) in DIR"
 ac_help="$ac_help
+  --with-gdbm=DIR         use GNU DBM in DIR"
+ac_help="$ac_help
   --with-libpcap=DIR      use libpcap in DIR"
 ac_help="$ac_help
   --with-libnet=DIR       use libnet in DIR"
diff -Nur dsniff-2.3/record.c dsniff-2.3.patched/record.c
--- dsniff-2.3/record.c	2000-11-14 16:51:02.000000000 +0100
+++ dsniff-2.3.patched/record.c	2005-06-09 15:16:50.000000000 +0200
@@ -13,12 +13,7 @@
 #include <stdio.h>
 #include <time.h>
 #include <md5.h>
-#ifdef HAVE_DB_185_H
-#define DB_LIBRARY_COMPATIBILITY_API
-#include <db_185.h>
-#elif HAVE_DB_H
-#include <db.h>
-#endif
+#include <gdbm.h>
 #include <libnet.h>
 #include "options.h"
 #include "record.h"
@@ -34,7 +29,7 @@
 	struct netobj	data;
 };
 	
-static DB *db;
+GDBM_FILE dbf;
 
 static int
 xdr_rec(XDR *xdrs, struct rec *rec)
@@ -86,10 +81,10 @@
 	fflush(stdout);
 }
 
-static DBT *
+static datum
 record_hash(struct rec *rec)
 {
-	static DBT key;
+	static datum key;
 	static u_char hash[16];
 	MD5_CTX ctx;
 
@@ -102,16 +97,16 @@
 	MD5Update(&ctx, rec->data.n_bytes, rec->data.n_len);
 	MD5Final(hash, &ctx);
 
-	key.data = hash;
-	key.size = sizeof(hash);
+	key.dptr = hash;
+	key.dsize = sizeof(hash);
 	
-	return (&key);
+	return (key);
 }
 
 static int
 record_save(struct rec *rec)
 {
-	DBT *key, data;
+	datum key, data;
 	XDR xdrs;
 	u_char buf[2048];
 	
@@ -120,15 +115,15 @@
 	if (!xdr_rec(&xdrs, rec))
 		return (0);
 	
-	data.data = buf;
-	data.size = xdr_getpos(&xdrs);
+	data.dptr = buf;
+	data.dsize = xdr_getpos(&xdrs);
 	
 	xdr_destroy(&xdrs);
 
 	key = record_hash(rec);
 	
-	if (db->put(db, key, &data, R_NOOVERWRITE) == 0)
-		db->sync(db, 0);
+	if (gdbm_store(dbf, key, data, GDBM_INSERT) == 0)
+		gdbm_sync(dbf);
 	
 	return (1);
 }
@@ -136,18 +131,22 @@
 void
 record_dump(void)
 {
-	DBT key, data;
+	datum nextkey, data;
 	XDR xdrs;
 	struct rec rec;
 	
-	while (db->seq(db, &key, &data, R_NEXT) == 0) {	
+	data = gdbm_firstkey ( dbf );
+	while (data.dptr) {	
+		nextkey = gdbm_nextkey ( dbf, data );
 		memset(&rec, 0, sizeof(rec));
-		xdrmem_create(&xdrs, data.data, data.size, XDR_DECODE);
+		xdrmem_create(&xdrs, data.dptr, data.dsize, XDR_DECODE);
 		
 		if (xdr_rec(&xdrs, &rec)) {
 			record_print(&rec);
 		}
 		xdr_destroy(&xdrs);
+		free(data.dptr);
+		data = nextkey;
 	}
 }
 
@@ -157,14 +156,14 @@
 	int flags, mode;
 	
 	if (Opt_read) {
-		flags = O_RDONLY;
+		flags = GDBM_READER;
 		mode = 0;
 	}
 	else {
-		flags = O_RDWR|O_CREAT;
+		flags = GDBM_WRCREAT;
 		mode = S_IRUSR|S_IWUSR;
 	}
-	if ((db = dbopen(file, flags, mode, DB_BTREE, NULL)) == NULL)
+	if ((dbf = gdbm_open(file, 1024, flags, mode, NULL)) == NULL)
 		return (0);
 
 	return (1);
@@ -203,6 +202,6 @@
 void
 record_close(void)
 {
-	db->close(db);
+	gdbm_close(dbf);
 }