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