Logoj0ke.net Open Build Service > Projects > home:jg:dns > pdns > pdns-2.9.22-axfr-patch
Sign Up | Log In

File pdns-2.9.22-axfr-patch of Package pdns

x
 
1
diff -ur pdns-2.9.22/debian-pdns/rules pdns-2.9.22-IX/debian-pdns/rules
2
--- pdns-2.9.22/debian-pdns/rules   2008-11-16 18:21:08.000000000 +0100
3
+++ pdns-2.9.22-IX/debian-pdns/rules    2009-05-04 09:19:04.000000000 +0200
4
@@ -2,8 +2,10 @@
5
 
6
 tmpdir     := $(shell pwd)/debian-pdns/tmp
7
 be_tmpdir  := $(shell pwd)/debian-pdns/tmp-backend
8
-backends   := opendbx ldap mysql pipe gmysql gpgsql gsqlite gsqlite3
9
-debs       := opendbx ldap mysql pipe pgsql sqlite sqlite3
10
+#backends  := opendbx ldap mysql pipe gmysql gpgsql gsqlite gsqlite3
11
+#debs      := opendbx ldap mysql pipe pgsql sqlite sqlite3
12
+backends   := mysql pipe gmysql
13
+debs       := mysql pipe
14
 
15
 binary-doc:
16
    -make -C pdns/docs html/index.html
17
@@ -51,7 +53,7 @@
18
        --infodir='$${datadir}/info' \
19
        --mandir='$${datadir}/man' \
20
        --with-pgsql-lib=/opt/postgresql/lib --with-pgsql-includes=/opt/postgresql/include \
21
-       --with-modules="mysql gmysql gpgsql pipe pdns gsqlite gsqlite3 geo" \
22
+       --with-modules="mysql gmysql pipe pdns" \
23
        --with-dynmodules="" \
24
        --enable-static-binaries 
25
    make
26
diff -ur pdns-2.9.22/modules/gmysqlbackend/gmysqlbackend.cc pdns-2.9.22-IX/modules/gmysqlbackend/gmysqlbackend.cc
27
--- pdns-2.9.22/modules/gmysqlbackend/gmysqlbackend.cc  2008-02-03 13:14:00.000000000 +0100
28
+++ pdns-2.9.22-IX/modules/gmysqlbackend/gmysqlbackend.cc   2009-04-30 17:00:15.000000000 +0200
29
@@ -75,6 +75,7 @@
30
     declare(suffix,"info-all-master-query","", "select id,name,master,last_check,notified_serial,type from domains where type='MASTER'");
31
     declare(suffix,"delete-zone-query","", "delete from records where domain_id=%d");
32
 
33
+    declare(suffix,"lookup-axfr-allow","", "select zone_grants from domains where name='%s'");
34
 
35
   }
36
   
37
diff -ur pdns-2.9.22/pdns/backends/gsql/gsqlbackend.cc pdns-2.9.22-IX/pdns/backends/gsql/gsqlbackend.cc
38
--- pdns-2.9.22/pdns/backends/gsql/gsqlbackend.cc   2008-12-06 20:43:50.000000000 +0100
39
+++ pdns-2.9.22-IX/pdns/backends/gsql/gsqlbackend.cc    2009-05-05 12:43:04.000000000 +0200
40
@@ -16,10 +16,78 @@
41
 #include "pdns/ahuexception.hh"
42
 #include "pdns/logger.hh"
43
 #include "pdns/arguments.hh"
44
+#include "pdns/iputils.hh"
45
 #include <boost/algorithm/string.hpp>
46
 #include <sstream>
47
+
48
 using namespace boost;
49
 
50
+bool GSQLBackend::checkAXFRByZone(const std::string& name , const std::string& ip)
51
+{
52
+//    L << Logger::Warning 
53
+//      << "ZONE-AXFR: checking " << name << " with " << ip << std::endl;
54
+
55
+    char output[1024];
56
+
57
+    snprintf( output,sizeof(output)-1,
58
+              d_LookupAxfrAllow.c_str(),name.c_str()
59
+             );
60
+    
61
+    L << Logger::Warning 
62
+      << "ZONE-AXFR: checking " << name << " with " << ip << std::endl
63
+      << "STATEMENT: "<< output << std::endl;
64
+
65
+    try 
66
+    {
67
+           d_db->doQuery(output, d_result);
68
+    }
69
+    catch(SSqlException &e) 
70
+      {
71
+        throw AhuException("GSQLBackend unable to select AXFR-by Zone . name " 
72
+                         + name  
73
+                         + " with ip "
74
+                         + ip
75
+                         + " : "
76
+                         + e.txtReason());
77
+      }
78
+
79
+    if(!d_result.size())
80
+      return false;
81
+
82
+    if(d_result.size() > 1)
83
+      throw AhuException("Ambigous entries ' "  
84
+                         + name  
85
+                         + "' exists more than once");
86
+    
87
+    SSql::row_t row(d_result[0]);
88
+    SSql::row_t::const_reverse_iterator zone_str_iter(row.rbegin());
89
+    std::vector<std::string> allowed_ips;
90
+
91
+    stringtok(allowed_ips, *zone_str_iter, ";");
92
+    std::vector<std::string>::iterator iter(allowed_ips.begin()),
93
+                                       end(allowed_ips.end());
94
+
95
+    for(;iter!=end;++iter)
96
+    {
97
+         trim(*iter);
98
+
99
+         L << Logger::Warning << "ZONE-AXFR: comparing '" << *iter << "' with '" << ip << "'"<< std::endl; 
100
+
101
+         if(*iter == ip) return true;
102
+
103
+         // check for netmasks
104
+         if( (*iter).find_first_of('/') != std::string::npos ) // found a mask
105
+         {
106
+              L << Logger::Warning << "detected mask " << std::endl;
107
+              Netmask mask(*iter);
108
+              if(mask.match(ip)) return true;
109
+         }
110
+         
111
+
112
+    }
113
+    return false;
114
+}
115
+
116
 void GSQLBackend::setNotified(uint32_t domain_id, uint32_t serial)
117
 {
118
   char output[1024];
119
@@ -239,6 +307,7 @@
120
   d_UpdateLastCheckofZoneQuery=getArg("update-lastcheck-query");
121
   d_InfoOfAllMasterDomainsQuery=getArg("info-all-master-query");
122
   d_DeleteZoneQuery=getArg("delete-zone-query");
123
+  d_LookupAxfrAllow=getArg("lookup-axfr-allow");
124
 }
125
 
126
 
127
diff -ur pdns-2.9.22/pdns/backends/gsql/gsqlbackend.hh pdns-2.9.22-IX/pdns/backends/gsql/gsqlbackend.hh
128
--- pdns-2.9.22/pdns/backends/gsql/gsqlbackend.hh   2008-02-03 13:13:59.000000000 +0100
129
+++ pdns-2.9.22-IX/pdns/backends/gsql/gsqlbackend.hh    2009-04-30 17:00:15.000000000 +0200
130
@@ -21,6 +21,9 @@
131
     d_db=db;
132
   }
133
   
134
+   //checks if a zone is allowed to check axfr-data
135
+  bool checkAXFRByZone(const std::string& name , const std::string& ip);
136
+    
137
   string sqlEscape(const string &name);
138
   void lookup(const QType &, const string &qdomain, DNSPacket *p=0, int zoneId=-1);
139
   bool list(const string &target, int domain_id);
140
@@ -65,6 +68,7 @@
141
   string d_UpdateSerialOfZoneQuery;
142
   string d_UpdateLastCheckofZoneQuery;
143
   string d_InfoOfAllMasterDomainsQuery;
144
-  string d_DeleteZoneQuery;        
145
+  string d_DeleteZoneQuery;
146
+  string d_LookupAxfrAllow;        
147
 
148
 };
149
diff -ur pdns-2.9.22/pdns/common_startup.cc pdns-2.9.22-IX/pdns/common_startup.cc
150
--- pdns-2.9.22/pdns/common_startup.cc  2008-11-19 18:56:52.000000000 +0100
151
+++ pdns-2.9.22-IX/pdns/common_startup.cc   2009-04-30 17:00:15.000000000 +0200
152
@@ -127,6 +127,9 @@
153
 
154
   ::arg().set("max-cache-entries", "Maximum number of cache entries")="1000000";
155
   ::arg().set("entropy-source", "If set, read entropy from this file")="/dev/urandom";
156
+
157
+  ::arg().set("axfr-by-zone","allows configuration of axfr-allows by zone")="yes";
158
+  ::arg().setSwitch("axfr-by-zone","allows configuration of axfr-allows by zone")="yes";
159
 }
160
 
161
 void declareStats(void)
162
diff -ur pdns-2.9.22/pdns/dnsbackend.cc pdns-2.9.22-IX/pdns/dnsbackend.cc
163
--- pdns-2.9.22/pdns/dnsbackend.cc  2008-11-15 21:32:46.000000000 +0100
164
+++ pdns-2.9.22-IX/pdns/dnsbackend.cc   2009-04-30 17:00:15.000000000 +0200
165
@@ -25,6 +25,11 @@
166
 #include <sys/types.h>
167
 #include "dnspacket.hh"
168
 
169
+bool DNSBackend::checkAXFRByZone(const std::string& name , const std::string& ip)
170
+{
171
+  return false;
172
+}
173
+
174
 string DNSBackend::getRemote(DNSPacket *p)
175
 {
176
   return p->getRemote();
177
diff -ur pdns-2.9.22/pdns/dnsbackend.hh pdns-2.9.22-IX/pdns/dnsbackend.hh
178
--- pdns-2.9.22/pdns/dnsbackend.hh  2008-02-03 13:13:59.000000000 +0100
179
+++ pdns-2.9.22-IX/pdns/dnsbackend.hh   2009-04-30 17:00:15.000000000 +0200
180
@@ -77,6 +77,8 @@
181
       if the backend does not consider itself responsible for the id passed.
182
       \param domain_id ID of which a list is requested
183
   */
184
+  virtual bool checkAXFRByZone(const std::string& name , const std::string& ip);
185
+
186
   virtual bool list(const string &target, int domain_id)=0;  
187
 
188
   virtual ~DNSBackend(){};
189
diff -ur pdns-2.9.22/pdns/misc.cc pdns-2.9.22-IX/pdns/misc.cc
190
--- pdns-2.9.22/pdns/misc.cc    2008-11-15 21:32:46.000000000 +0100
191
+++ pdns-2.9.22-IX/pdns/misc.cc 2009-04-30 17:00:15.000000000 +0200
192
@@ -232,6 +232,10 @@
193
 
194
     while (replen) {
195
       ret = write(outsock, buffer, replen);
196
+      while(ret == -1 && errno == EAGAIN) {
197
+        Utility::usleep(1);
198
+        ret = write(outsock, buffer, replen);
199
+      }
200
       if(ret < 0) {
201
    if(errno==EAGAIN) { // wait, we might've exhausted the window
202
      while(waitForRWData(outsock, false, 1, 0)==0)
203
diff -ur pdns-2.9.22/pdns/tcpreceiver.cc pdns-2.9.22-IX/pdns/tcpreceiver.cc
204
--- pdns-2.9.22/pdns/tcpreceiver.cc 2008-11-19 18:21:11.000000000 +0100
205
+++ pdns-2.9.22-IX/pdns/tcpreceiver.cc  2009-05-04 10:35:51.000000000 +0200
206
@@ -346,16 +346,42 @@
207
   if(::arg().mustDo("disable-axfr"))
208
     return false;
209
 
210
-  if( ::arg()["allow-axfr-ips"].empty() || d_ng.match( (ComboAddress *) &q->remote ) )
211
-    return true;
212
+  if(::arg().mustDo("axfr-by-zone") )
213
+  {
214
+       //DNSBackend *backend = s_P->getBackend();
215
+       PacketHandler P;
216
+       DNSBackend *backend = P.getBackend();
217
+       if(backend->checkAXFRByZone( q->qdomain , q->getRemote()) ) 
218
+       {
219
+            L << Logger::Warning
220
+              <<"Approved zone-based AXFR of '"<<q->qdomain
221
+              << q->getRemote()<<endl;
222
+            return true;
223
+       }
224
+       //a empty list is a failure in case of 'axfr-by-zone'
225
+       else if(d_ng.match( (ComboAddress *) &q->remote ) )
226
+       {
227
+            L << Logger::Warning  << "allowed by config file" << endl;
228
+            return true;
229
+       }
230
+  }
231
+  else
232
+  {
233
+ //      L << Logger::Warning<< "no axfr-by-zone" <<endl;
234
+       if(::arg()["allow-axfr-ips"].empty() 
235
+           || d_ng.match( (ComboAddress *) &q->remote ) )
236
+            return true;
237
+  }
238
 
239
   extern CommunicatorClass Communicator;
240
 
241
   if(Communicator.justNotified(q->qdomain, q->getRemote())) { // we just notified this ip 
242
-    L<<Logger::Warning<<"Approved AXFR of '"<<q->qdomain<<"' from recently notified slave "<<q->getRemote()<<endl;
243
+    L << Logger::Warning << "Approved AXFR of '" << q->qdomain << "' from recently notified slave " << q->getRemote() << endl;
244
     return true;
245
   }
246
 
247
+  L << Logger::Warning << "AXFR FAILED" << endl;
248
+
249
   return false;
250
 }
251
 
252
diff -ur pdns-2.9.22/pdns/ueberbackend.cc pdns-2.9.22-IX/pdns/ueberbackend.cc
253
--- pdns-2.9.22/pdns/ueberbackend.cc    2008-11-27 22:56:33.000000000 +0100
254
+++ pdns-2.9.22-IX/pdns/ueberbackend.cc 2009-04-30 17:00:15.000000000 +0200
255
@@ -60,6 +60,15 @@
256
 #define RTLD_NOW RTLD_LAZY
257
 #endif
258
 
259
+bool UeberBackend::checkAXFRByZone( const std::string& name , const std::string& ip)
260
+{
261
+  for ( vector< DNSBackend * >::iterator i = backends.begin(); i != backends.end(); ++i )
262
+  {
263
+    if(( *i )->checkAXFRByZone( name , ip) ) return true;
264
+  }
265
+  return false;
266
+}
267
+
268
 //! Loads a module and reports it to all UeberBackend threads
269
 bool UeberBackend::loadmodule(const string &name)
270
 {
271
diff -ur pdns-2.9.22/pdns/ueberbackend.hh pdns-2.9.22-IX/pdns/ueberbackend.hh
272
--- pdns-2.9.22/pdns/ueberbackend.hh    2008-02-03 13:13:59.000000000 +0100
273
+++ pdns-2.9.22-IX/pdns/ueberbackend.hh 2009-04-30 17:00:15.000000000 +0200
274
@@ -57,6 +57,7 @@
275
   UeberBackend();
276
   UeberBackend(const string &);
277
   ~UeberBackend();
278
+  virtual bool checkAXFRByZone(const std::string& name , const std::string& ip);
279
   typedef DNSBackend *BackendMaker(); //!< typedef for functions returning pointers to new backends
280
 
281
   bool superMasterBackend(const string &ip, const string &domain, const vector<DNSResourceRecord>&nsset, string *account, DNSBackend **db);
282