File: DB2Backend.cc

package info (click to toggle)
pdns 2.9.20-8
  • links: PTS
  • area: main
  • in suites: etch-m68k
  • size: 4,640 kB
  • ctags: 3,511
  • sloc: cpp: 24,567; sh: 17,754; makefile: 360; yacc: 189; lex: 131; sql: 69; perl: 39
file content (623 lines) | stat: -rw-r--r-- 20,064 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
// $Id: DB2Backend.cc 477 2005-09-03 18:15:37Z ahu $

#include <string>
#include <unistd.h>
#include <stdlib.h>
#include <sstream>

using namespace std;

#include <dns.hh>
#include <dnsbackend.hh>
#include <dnspacket.hh>
#include <ueberbackend.hh>
#include <ahuexception.hh>
#include <logger.hh>
#include <arguments.hh>

#include "DB2Exception.hh"
#include "DB2Backend.hh"

static const string kBackendName="[DB2Backend]";

static const int kForwardQuery            = 0;
static const int kForwardByZoneQuery      = 1;
static const int kForwardAnyQuery         = 2;
static const int kForwardWildcardQuery    = 3;
static const int kForwardWildcardAnyQuery = 4;

static const int kListQuery               = 5;
      
static const int kNumQueries              = 6;

static const char *kQueries[kNumQueries] =
{
   // ForwardQuery
   "select Content, TimeToLive, Priority, Type, ZoneId, 0 as ChangeDate, Name from Records where Name = ? and type = ?",
   
   // ForwardByZoneQuery
   "select Content, TimeToLive, Priority, Type, ZoneId, 0 as ChangeDate, Name from Records where Name = ? and Type = ? and ZoneId = ?",
         
   // ForwardAnyQuery
   "select Content, TimeToLive, Priority, Type, ZoneId, 0 as ChangeDate, Name from Records where Name = ?",
   
   // ForwardWildcardQuery
   "select Content, TimeToLive, Priority, Type, ZoneId, 0 as ChangeDate, Name from Records where Name like ? and Type = ?",
   
   // ForwardWildcardAnyQuery
   "select Content, TimeToLive, Priority, Type, ZoneId, 0 as ChangeDate, Name from Records where Name like ?",
   
   // ListQuery
   "select Content, TimeToLive, Priority, Type, ZoneId, 0 as ChangeDate, Name from Records where ZoneId = ?"
};

static const char *kSoaQuery = "select Id,Hostmaster,Serial from Zones where Active = 1 and Name = ?";

DB2Backend::DB2Backend(const string &suffix)
{
   SQLRETURN theError;

   // Initialize the handles
   mConnection = SQL_NULL_HANDLE;
   mEnvironment = SQL_NULL_HANDLE;
   for (int i = 0; i < kNumQueries; i++) {
      mStatements[i] = SQL_NULL_HANDLE;
   }

   try
   {
      // Allocate the Environment Handle
      theError = SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &mEnvironment);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError);
      }

      // Allocate a Connection Handle
      theError = SQLAllocHandle(SQL_HANDLE_DBC, mEnvironment, &mConnection);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_ENV, mEnvironment);
      }

      // Try to connect to the database
      theError = SQLConnect(mConnection, (SQLCHAR*) arg()["db2-"+suffix+"server"].c_str(), SQL_NTS, (SQLCHAR*) arg()["db2-"+suffix+"user"].c_str(), SQL_NTS, (SQLCHAR*) arg()["db2-"+suffix+"password"].c_str(), SQL_NTS);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_DBC, mConnection);
      }

      // Set autocommit to off
      theError = SQLSetConnectAttr(mConnection, SQL_ATTR_AUTOCOMMIT, (SQLPOINTER) SQL_AUTOCOMMIT_OFF, SQL_NTS);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_DBC, mConnection);
      }

      // Prepare the statements
      for (int i = 0; i < kNumQueries; i++)
      {
         // Allocate a Statement Handle
         theError = SQLAllocHandle(SQL_HANDLE_STMT, mConnection, &(mStatements[i]));
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mConnection);
         }         

         // Prepare the statement
         theError = SQLPrepare(mStatements[i], (SQLCHAR*) kQueries[i], SQL_NTS);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }

         //
         // Bind Parameters
         //

         // Bind the Name parameter to all queries except the list statements
         if (i != kListQuery) {
            theError = SQLBindParameter(mStatements[i], 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 256, 0, mParamName, 256, NULL);
            if (theError != SQL_SUCCESS) {
               throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
            }
         }

         // Bind the Type parameter only to the kForwardQuery, kForwardByZoneQuery and kForwardWildcardQuery statements
         if (i == kForwardQuery || i == kForwardByZoneQuery || i == kForwardWildcardQuery) {
            theError = SQLBindParameter(mStatements[i], 2, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 256, 0, mParamType, 256, NULL);
            if (theError != SQL_SUCCESS) {
               throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
            }
         }

         // Bind the ZoneId parameter for the kForwardByZoneQuery and kListQuery queries
         if (i == kForwardByZoneQuery || i == kListQuery) {
            int theIndex = (i == kForwardByZoneQuery) ? 3 : 1;            
            theError = SQLBindParameter(mStatements[i], theIndex, SQL_PARAM_INPUT, SQL_C_LONG, SQL_INTEGER, 0, 0, &mParamZoneId, 0, NULL);
            if (theError != SQL_SUCCESS) {
               throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
            }            
         }

         //
         // Bind Columns
         //

         // Bind the Content column
         mResultContentIndicator = 0;
         theError = SQLBindCol(mStatements[i], 1, SQL_C_CHAR, mResultContent, sizeof(mResultContent), &mResultContentIndicator);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }

         // Bind the TimeToLive column
         mResultTimeToLiveIndicator = 0;
         theError = SQLBindCol(mStatements[i], 2, SQL_C_LONG, &mResultTimeToLive, sizeof(mResultTimeToLive), &mResultTimeToLiveIndicator);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }

         // Bind the Priority column
         mResultPriorityIndicator = 0;
         theError = SQLBindCol(mStatements[i], 3, SQL_C_LONG, &mResultPriority, sizeof(mResultZoneId), &mResultPriorityIndicator);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }

         // Bind the Type column
         mResultTypeIndicator = 0;
         theError = SQLBindCol(mStatements[i], 4, SQL_C_CHAR, mResultType, sizeof(mResultType), &mResultTypeIndicator);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }

         // Bind the ZoneId column
         mResultZoneIdIndicator = 0;
         theError = SQLBindCol(mStatements[i], 5, SQL_C_LONG, &mResultZoneId, sizeof(mResultZoneId), &mResultZoneIdIndicator);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }

         // Bind the ChangeDate column
         mResultChangeDateIndicator = 0;
         theError = SQLBindCol(mStatements[i], 6, SQL_C_LONG, &mResultChangeDate, sizeof(mResultChangeDate), &mResultChangeDateIndicator);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }
         
         // Bind the Name column
         mResultNameIndicator = 0;
         theError = SQLBindCol(mStatements[i], 7, SQL_C_CHAR, mResultName, sizeof(mResultName), &mResultNameIndicator);
         if (theError != SQL_SUCCESS) {
            throw DB2Exception(theError, SQL_HANDLE_DBC, mStatements[i]);
         }

         mStatementStates[i] = false;
      }

      //
      // Construct the SOA Query
      //

      // Prepare the SOA Query
      theError = SQLAllocHandle(SQL_HANDLE_STMT, mConnection, &mSoaStatement);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_DBC, mConnection);
      }

      theError = SQLPrepare(mSoaStatement, (SQLCHAR*) kSoaQuery, SQL_NTS);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
      }

      // Bind the Name parameter      
      theError = SQLBindParameter(mSoaStatement, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 256, 0, mSoaParamName, 256, NULL);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
      }

      // Bind the ZoneId column
      mSoaResultZoneIdIndicator = 0;
      theError = SQLBindCol(mSoaStatement, 1, SQL_C_LONG, &mSoaResultZoneId, sizeof(mSoaResultZoneId), &mSoaResultZoneIdIndicator);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
      }      

      // Bind the Hostmaster column
      mSoaResultHostmasterIndicator = 0;
      theError = SQLBindCol(mSoaStatement, 2, SQL_C_CHAR, mSoaResultHostmaster, 256, &mSoaResultHostmasterIndicator);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
      }

      // Bind the Serial column
      mSoaResultSerialIndicator = 0;
      theError = SQLBindCol(mSoaStatement, 3, SQL_C_LONG, &mSoaResultSerial, sizeof(mSoaResultSerial), &mSoaResultSerialIndicator);
      if (theError != SQL_SUCCESS) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
      }
   }
   
   catch (DB2Exception& theException)
   {
      //
      // Print out diagnostics
      //
      
      int theNativeError;
      string theSqlState, theSqlMessage;
      
      while (theException.GetNextSqlError(theNativeError, theSqlState, theSqlMessage) == true) {
         L << Logger::Warning << kBackendName << " Statement initialization failed with error " << theNativeError << endl;
         L << Logger::Warning << kBackendName << "  SQL State : " << theSqlState << endl;
         L << Logger::Warning << kBackendName << "  SQL Msg   : " << theSqlMessage << endl;
      }
      
      this->Cleanup();
      throw AhuException("DB2Backend Failed to Start");
   }
   
   L << Logger::Warning << kBackendName << " Connection succeeded" << endl;
}

void DB2Backend::Cleanup()
{
   for (int i = 0; i < kNumQueries; i++) {
      if (mStatements[i] != SQL_NULL_HANDLE) {
         (void) SQLFreeHandle(SQL_HANDLE_STMT, mStatements[i]);
      }
   }

   if (mConnection != SQL_NULL_HANDLE) {
      (void) SQLFreeHandle(SQL_HANDLE_DBC, mConnection);
   }
   
   if (mEnvironment != SQL_NULL_HANDLE) {
      (void) SQLFreeHandle(SQL_HANDLE_ENV, mEnvironment);
   }
}

DB2Backend::~DB2Backend()
{
   this->Cleanup();
}

void DB2Backend::lookup(const QType &qtype, const string &qname, DNSPacket *pkt_p, int zoneId )
{
   SQLRETURN theError;

   //
   // Choose the right query. All this logic and the query types could be
   // moved to the API. Saves duplicate code in backends.
   //

   int theQueryType = -1;

   if (qname[0] == '%') {
      if (qtype.getCode() == 255) {
         theQueryType = kForwardWildcardAnyQuery;
      } else {
         theQueryType = kForwardWildcardQuery;
      }
   } else {
      if (qtype.getCode() == 255) {
         theQueryType = kForwardAnyQuery;
      } else {
         if (zoneId != -1) {
            theQueryType = kForwardByZoneQuery;
         } else {
            theQueryType = kForwardQuery;
         }
      }
   }
   
   //
   // Fill in the correct query parameters
   //

   //cerr << ">>>>>>>> Query = " << kQueries[theQueryType] << endl;
   
   switch (theQueryType)
   {
      case kForwardQuery:
      case kForwardWildcardQuery:
	 strncpy(mParamName, qname.c_str(), sizeof(mParamName));
         strncpy(mParamType, qtype.getName().c_str(), sizeof(mParamType));
         //cerr << ">>>>>>>>  Name = " << mParamName << " Type = " << mParamType << endl;
	 break;

      case kForwardByZoneQuery:
	 strncpy(mParamName, qname.c_str(), sizeof(mParamName));
	 strncpy(mParamType, qtype.getName().c_str(), sizeof(mParamType));	 
	 mParamZoneId = zoneId;
         //cerr << ">>>>>>>>  Name = " << mParamName << " Type = " << mParamType << " ZoneId = " << mParamZoneId << endl;
	 break;

      case kForwardAnyQuery:
      case kForwardWildcardAnyQuery:
	 strncpy(mParamName, qname.c_str(), sizeof(mParamName));
         //cerr << ">>>>>>>>  Name = " << mParamName << endl;
	 break;
   }

   //
   // Execute the query
   //

   try
   {
      //
      // Close the cursor if it is in use
      //

      if (mStatementStates[theQueryType] == true) {
         theError = SQLCloseCursor(mStatements[theQueryType]);
         if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO) {
            throw DB2Exception(theError, SQL_HANDLE_STMT, mStatements[theQueryType]);
         }
      }

      //
      // Execute the query
      //

      mResultContent[0] = mResultType[0] = mResultName[0] = 0x00;
      mResultTimeToLive = mResultPriority = mResultZoneId = mResultChangeDate = 0;
      
      theError = SQLExecute(mStatements[theQueryType]);
      if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO && theError != SQL_NO_DATA_FOUND) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mStatements[theQueryType]);
      }

      mCurrentStatement = mStatements[theQueryType];
      mStatementStates[theQueryType] = true;
   }
   
   catch (DB2Exception& theException)
   {
      //
      // Print out diagnostics
      //
      
      int theNativeError;
      string theSqlState, theSqlMessage;
      
      while (theException.GetNextSqlError(theNativeError, theSqlState, theSqlMessage) == true) {
         L << Logger::Warning << kBackendName << " SQLExecute() failed with error " << theNativeError << endl;
         L << Logger::Warning << kBackendName << "  SQL State : " << theSqlState << endl;
         L << Logger::Warning << kBackendName << "  SQL Msg   : " << theSqlMessage << endl;
      }

      //
      // Rethrow for the nameserver
      //
      
      throw AhuException("Execute failed");
   }
}

bool DB2Backend::list(int inZoneId)
{
   SQLRETURN theError;
   bool theResult = false;

   try
   {
      //
      // Close the cursor
      //
      
      if (mStatementStates[kListQuery] == true) {
         theError = SQLCloseCursor(mStatements[kListQuery]);
         if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO) {
            throw DB2Exception(theError, SQL_HANDLE_STMT, mCurrentStatement);
         }
      }

      //
      // Execute the query
      //

      mParamZoneId = inZoneId;

      theError = SQLExecute(mStatements[kListQuery]);
      if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO && theError != SQL_NO_DATA_FOUND) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mStatements[kListQuery]);
      }

      mCurrentStatement = mStatements[kListQuery];
      mStatementStates[kListQuery] = true;

      if (theResult != SQL_NO_DATA_FOUND) {
         theResult = true;
      }
   }

   catch (DB2Exception& theException)
   {
      throw AhuException("List failed");
   }

   return theResult;
}

bool DB2Backend::get(DNSResourceRecord& outRecord)
{
   bool theResult = false;

   try
   {
      //
      // Fetch a record
      //

      SQLRETURN theError = SQLFetch(mCurrentStatement);
      if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO && theError != SQL_NO_DATA_FOUND) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mCurrentStatement);
      }

      //
      // If we have data then return it
      //
   
      //cerr << ">>>>>>>> Get theError = " << theError << endl;

      if (theError != SQL_NO_DATA_FOUND)
      {
         //cerr << ">>>>>>>> Name    = " << mResultName << endl;
         //cerr << ">>>>>>>> Content = " << mResultContent << endl;
         //cerr << ">>>>>>>> Type    = " << mResultType << endl;
         
         outRecord.content       = mResultContent;
         outRecord.ttl           = mResultTimeToLive;
         outRecord.priority      = mResultPriority;
         outRecord.qtype         = mResultType;
         outRecord.domain_id     = mResultZoneId;
         outRecord.last_modified = mResultChangeDate;
         outRecord.qname         = mResultName;
         
         theResult = true;
      }
   }

   catch (DB2Exception& theException)
   {
      //
      // Print out diagnostics
      //
      
      int theNativeError;
      string theSqlState, theSqlMessage;
      
      while (theException.GetNextSqlError(theNativeError, theSqlState, theSqlMessage) == true) {
         L << Logger::Warning << kBackendName << " SQLFetch() failed with error " << theNativeError << endl;
         L << Logger::Warning << kBackendName << "  SQL State : " << theSqlState << endl;
         L << Logger::Warning << kBackendName << "  SQL Msg   : " << theSqlMessage << endl;
      }

      //
      // Rethrow for the nameserver
      //
      
      throw AhuException("Fetch failed");
   }
   
   return theResult;
}

bool DB2Backend::getSOA(const string& inZoneName, SOAData& outSoaData)
{
   bool theResult = false;
   
   try
   {
      //
      // Execute the query
      //

      strncpy(mSoaParamName, inZoneName.c_str(), sizeof(mSoaParamName));

      SQLRETURN theError = SQLExecute(mSoaStatement);
      if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO && theError != SQL_NO_DATA_FOUND) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
      }      

      if (theError != SQL_NO_DATA_FOUND)
      {
         mSoaResultZoneId = mSoaResultSerial = 0;
         mSoaResultHostmaster[0] = mSoaResultNameserver[0] = 0x00;

         theError = SQLFetch(mSoaStatement);
         if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO) {
            throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
         }
         
         outSoaData.domain_id   = mSoaResultZoneId;         
         outSoaData.nameserver  = arg()["default-soa-name"];
         outSoaData.hostmaster  = mSoaResultHostmaster;
         outSoaData.serial      = mSoaResultSerial;         
         outSoaData.refresh     = 10800;
         outSoaData.retry       = 3600;
         outSoaData.expire      = 604800;
         outSoaData.default_ttl = 3600;
         
         theResult = true;
      }
      
      //
      // Close the cursor
      //

      theError = SQLCloseCursor(mSoaStatement);
      if (theError != SQL_SUCCESS && theError != SQL_SUCCESS_WITH_INFO) {
         throw DB2Exception(theError, SQL_HANDLE_STMT, mSoaStatement);
      }
   }

   catch (DB2Exception& theException)
   {
      //
      // Print out diagnostics
      //
      
      int theNativeError;
      string theSqlState, theSqlMessage;
      
      while (theException.GetNextSqlError(theNativeError, theSqlState, theSqlMessage) == true) {
         L << Logger::Warning << kBackendName << " SOA Record Lookup Failed: " << theNativeError << endl;
         L << Logger::Warning << kBackendName << "  SQL State : " << theSqlState << endl;
         L << Logger::Warning << kBackendName << "  SQL Msg   : " << theSqlMessage << endl;
      }

      //
      // Rethrow for the nameserver
      //
      
      throw AhuException("GetSOA failed");
   }
   
   return theResult;
}

//! For the dynamic loader
DNSBackend *DB2Backend::maker()
{
   DNSBackend *theBackend;
   
   try {
      theBackend = new DB2Backend;
   } catch (...) {
      theBackend = NULL;
   }
   
   return theBackend;
}

class DB2Factory : public BackendFactory
{
   public:

      DB2Factory() : BackendFactory("db2") {}
  
      void declareArguments(const string &suffix="")
      {
	 declare(suffix,"server","Server","powerdns");
	 declare(suffix,"user","User","powerdns");
	 declare(suffix,"password","Password","powerdns");
      }
      
      DNSBackend *make(const string &suffix="")
      {
	 return new DB2Backend(suffix);
      }
};


//! Magic class that is activated when the dynamic library is loaded
class DB2Loader
{
   public:

      Loader()
      {
	 BackendMakers().report(new DB2Factory);
	 L << Logger::Notice << kBackendName << " This is the DB2 module version "VERSION" ("__DATE__", "__TIME__") reporting" << endl;
      }
};

static DB2Loader db2loader;