~ubuntu-branches/ubuntu/quantal/maradns/quantal

« back to all changes in this revision

Viewing changes to update/1.4.08/maradns-1.4.07-secret_hash.patch

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2012-01-12 23:35:38 UTC
  • mto: This revision was merged to the branch mainline in revision 26.
  • Revision ID: package-import@ubuntu.com-20120112233538-5jkaqrh9nbqtf1ey
Tags: upstream-2.0.04+really1.4.09
ImportĀ upstreamĀ versionĀ 2.0.04+really1.4.09

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
diff -ur maradns-1.4.07/libs/MaraHash.c maradns-1.4.08/libs/MaraHash.c
 
2
--- maradns-1.4.07/libs/MaraHash.c      2011-11-11 16:58:34.000000000 -0600
 
3
+++ maradns-1.4.08/libs/MaraHash.c      2011-12-29 11:37:10.311564695 -0600
 
4
@@ -1,4 +1,4 @@
 
5
-/* Copyright (c) 2006 Sam Trenholme
 
6
+/* Copyright (c) 2006, 2011 Sam Trenholme
 
7
  *
 
8
  * TERMS
 
9
  *
 
10
@@ -32,6 +32,7 @@
 
11
 #include "JsStr.h"
 
12
 #endif
 
13
 #include "MaraHash.h"
 
14
+#include <stdio.h>
 
15
 
 
16
 /* Masks to limit the size of the hash */
 
17
 /* These are powers of two, minus one */
 
18
@@ -41,6 +42,8 @@
 
19
                           16777215, 33554431, 67108863, 134217727,
 
20
                           268435455, 536870911, 1073741823 };
 
21
 
 
22
+mhash_offset mhash_secret_add_constant = 7;
 
23
+
 
24
 /* Create a new, blank mhash object
 
25
    input: none
 
26
    output: pointer to the object in quesiton on success, NULL (0)
 
27
@@ -100,7 +103,7 @@
 
28
     /* Simple enough hash */
 
29
     while(point < max) {
 
30
         ret += (mhash_offset)(*point << shift);
 
31
-        shift += 7;
 
32
+        shift += mhash_secret_add_constant;
 
33
         shift %= hash_bits;
 
34
         point++;
 
35
         }
 
36
@@ -684,3 +687,21 @@
 
37
     return tuple->tuple_list[element];
 
38
     }
 
39
 
 
40
+/* Read three bytes from a filename and use that as a secret add constant */
 
41
+int mhash_set_add_constant(char *filename) {
 
42
+       FILE *read = 0;
 
43
+
 
44
+       read = fopen(filename,"rb");
 
45
+       if(read == NULL) {
 
46
+               return -1;
 
47
+       }
 
48
+       
 
49
+       mhash_secret_add_constant ^= getc(read);
 
50
+       mhash_secret_add_constant <<= 8;
 
51
+       mhash_secret_add_constant ^= getc(read);
 
52
+       mhash_secret_add_constant <<= 8;
 
53
+       mhash_secret_add_constant ^= getc(read);
 
54
+       fclose(read);
 
55
+       return 1;
 
56
+}
 
57
+
 
58
diff -ur maradns-1.4.07/server/MaraDNS.c maradns-1.4.08/server/MaraDNS.c
 
59
--- maradns-1.4.07/server/MaraDNS.c     2011-11-11 16:58:33.000000000 -0600
 
60
+++ maradns-1.4.08/server/MaraDNS.c     2011-12-29 11:41:54.315941513 -0600
 
61
@@ -1,4 +1,4 @@
 
62
-/* Copyright (c) 2002-2010 Sam Trenholme
 
63
+/* Copyright (c) 2002-2011 Sam Trenholme
 
64
  *
 
65
  * TERMS
 
66
  *
 
67
@@ -3952,6 +3952,24 @@
 
68
     int recurse_number_ports = 4096;
 
69
 #endif
 
70
 
 
71
+    /* First order of business: Initialize the hash */
 
72
+    if(mhash_set_add_constant(
 
73
+#ifdef MINGW32
 
74
+       "secret.txt"
 
75
+#else
 
76
+       "/dev/urandom"
 
77
+#endif
 
78
+               ) != 1) {
 
79
+       printf(
 
80
+#ifdef MINGW32
 
81
+       "Fatal error opening secret.txt"
 
82
+#else
 
83
+       "Fatal error opening /dev/urandom"
 
84
+#endif
 
85
+                       );
 
86
+                       return 32;
 
87
+       }
 
88
+    
 
89
     memset(&client,0,sizeof(client)); /* Initialize ya variables */
 
90
     clin = (struct sockaddr_in *)&client;
 
91
 #ifdef AUTHONLY