Index: dsniff-2.4/configure =================================================================== --- dsniff-2.4.orig/configure 2010-11-03 23:42:49.466000001 +0100 +++ dsniff-2.4/configure 2010-11-03 23:42:52.921000006 +0100 @@ -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" @@ -3059,7 +3061,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 Index: dsniff-2.4/record.c =================================================================== --- dsniff-2.4.orig/record.c 2010-11-03 23:42:49.471000001 +0100 +++ dsniff-2.4/record.c 2010-11-03 23:42:52.922000005 +0100 @@ -15,12 +15,7 @@ #include #include #include -#ifdef HAVE_DB_185_H -#define DB_LIBRARY_COMPATIBILITY_API -#include -#elif HAVE_DB_H -#include -#endif +#include #include #include "options.h" @@ -37,7 +32,7 @@ struct netobj data; }; -static DB *db; +GDBM_FILE dbf; static int xdr_rec(XDR *xdrs, struct rec *rec) @@ -64,7 +59,6 @@ tm = localtime(&rec->time); strftime(tstr, sizeof(tstr), "%x %X", tm); - srcp = libnet_host_lookup(rec->src, Opt_dns); dstp = libnet_host_lookup(rec->dst, Opt_dns); @@ -89,10 +83,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; @@ -105,16 +99,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]; @@ -123,15 +117,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); } @@ -139,18 +133,22 @@ void record_dump(void) { - DBT key, data; + datum nextkey, key, content; XDR xdrs; struct rec rec; - while (db->seq(db, &key, &data, R_NEXT) == 0) { + key = gdbm_firstkey(dbf); + while (key.dptr) { + nextkey = gdbm_nextkey(dbf, key); + content = gdbm_fetch(dbf, key); memset(&rec, 0, sizeof(rec)); - xdrmem_create(&xdrs, data.data, data.size, XDR_DECODE); - + xdrmem_create(&xdrs, content.dptr, content.dsize, XDR_DECODE); if (xdr_rec(&xdrs, &rec)) { record_print(&rec); } xdr_destroy(&xdrs); + free(key.dptr); + key = nextkey; } } @@ -158,16 +156,23 @@ record_init(char *file) { int flags, mode; - + // needed for gdbm_open, which does not have the option to create + // a database in memory + if(file == NULL) { + char *record_file = "/tmp/.dsniff.db"; + file = record_file; + } + 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); @@ -206,6 +211,6 @@ void record_close(void) { - db->close(db); + gdbm_close(dbf); }