#include #include #include #include #include #include #include #include struct czor_d { unsigned int spamcount; time_t spamtime; char sha1txt [40]; unsigned int hamcount; time_t hamtime; }; //------------------------------------------------------------------ void shaprint (char *psha); //------------------------------------------------------------------ main (int argc, char *argv[]) { GDBM_FILE dbf; struct czor_d *p; char hash [SHA_DIGEST_LENGTH]; datum key, data; int ret; if (argc != 3) { printf ("Give me a database filename please and a hash!\n"); exit (2); } // Now open a new or existing DB dbf = gdbm_open (argv[1], 0, GDBM_READER, 0600, 0); // Hash the input string SHA1 (argv[2], strlen (argv[2]), hash); // Load the blob key.dsize = SHA_DIGEST_LENGTH; key.dptr = hash; data = gdbm_fetch ( dbf, key ); if (data.dsize != 0) { // Print the hash printf ("hash: "); shaprint (hash); printf ("\n"); p = data.dptr; printf ("Spam Count: %d\n", p->spamcount); printf ("Spam Time: %s", ctime (&p->spamtime)); printf ("Ham Count: %d\n", p->hamcount); printf ("Ham Time: %s", ctime (&p->hamtime)); // Free the memory free (data.dptr); } // Close the database gdbm_close (dbf); } void shaprint (char *psha) { int i; for (i = 0; i < SHA_DIGEST_LENGTH; i++) printf ("%02x", psha[i] & 0xff); }