]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/zone2sql.cc
rec: ensure correct service user on debian
[thirdparty/pdns.git] / pdns / zone2sql.cc
index bbfed777dc35674d639e89f79306703ac29e25f9..a87abadd18c16b2093b5f291a3874f616fcd0e1f 100644 (file)
@@ -1,24 +1,25 @@
 /*
-    PowerDNS Versatile Database Driven Nameserver
-    Copyright (C) 2002 - 2011  PowerDNS.COM BV
+ * This file is part of PowerDNS or dnsdist.
+ * Copyright -- PowerDNS.COM B.V. and its contributors
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of version 2 of the GNU General Public License as
+ * published by the Free Software Foundation.
+ *
+ * In addition, for the avoidance of any doubt, permission is granted to
+ * link this program with OpenSSL and to (re)distribute the binaries
+ * produced as the result of such linking.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
 
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License version 2
-    as published by the Free Software Foundation
-
-    Additionally, the license of this program contains a special
-    exception which allows to distribute the program in binary form when
-    it is linked against OpenSSL.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
-*/
 /* accepts a named.conf or a zone as parameter and outputs heaps of sql */
 
 #ifdef HAVE_CONFIG_H
@@ -110,7 +111,7 @@ static void startNewTransaction()
     cout<<"BEGIN TRANSACTION;"<<endl;
 }
 
-static void emitDomain(const DNSName& domain, const vector<string> *masters = 0) {
+static void emitDomain(const DNSName& domain, const vector<ComboAddress> *masters = 0) {
   string iDomain = domain.toStringRootDot();
   if(!::arg().mustDo("slave")) {
     if(g_mode==POSTGRES || g_mode==MYSQL || g_mode==SQLITE) {
@@ -129,8 +130,8 @@ static void emitDomain(const DNSName& domain, const vector<string> *masters = 0)
     if(g_mode==POSTGRES || g_mode==MYSQL || g_mode==SQLITE) {
       string mstrs;
       if (masters != 0 && ! masters->empty()) {
-        for(const string& mstr :  *masters) {
-          mstrs.append(mstr);
+        for(const auto& mstr :  *masters) {
+          mstrs.append(mstr.toStringWithPortExcept(53));
           mstrs.append(1, ' ');
         }
       }
@@ -202,7 +203,7 @@ static void emitRecord(const DNSName& zoneName, const DNSName &DNSqname, const s
   else if(g_mode==POSTGRES) {
     cout<<"insert into records (domain_id, name, ordername, auth, type,content,ttl,prio,disabled) select id ,"<<
       sqlstr(toLower(qname))<<", "<<
-      sqlstr(toLower(labelReverse(makeRelative(qname, zname))))<<", '"<< (auth  ? 't' : 'f') <<"', "<<
+      sqlstr(DNSName(qname).makeRelative(DNSName(zname)).makeLowerCase().labelReverse().toString(" ", false))<<", '"<< (auth  ? 't' : 'f') <<"', "<<
       sqlstr(qtype)<<", "<<
       sqlstr(stripDotContent(content))<<", "<<ttl<<", "<<prio<<", '"<<(disabled ? 't': 'f') <<
       "' from domains where name="<<toLower(sqlstr(zname))<<";\n";
@@ -266,10 +267,8 @@ int main(int argc, char **argv)
 try
 {
     reportAllTypes();
-#if __GNUC__ >= 3
     std::ios_base::sync_with_stdio(false);
-#endif
-   
+  
     ::arg().setSwitch("gpgsql","Output in format suitable for default gpgsqlbackend")="no";
     ::arg().setSwitch("gmysql","Output in format suitable for default gmysqlbackend")="no";
     ::arg().setSwitch("mydns","Output in format suitable for default mydnsbackend")="no";
@@ -292,6 +291,7 @@ try
     ::arg().set("soa-expire-default","Do not change")="0";
 
     ::arg().setCmd("help","Provide a helpful message");
+    ::arg().setCmd("version","Print the version");
 
     S.declare("logmessages");
 
@@ -299,6 +299,11 @@ try
     string zonefile="";
 
     ::arg().parse(argc, argv);
+
+    if(::arg().mustDo("version")) {
+      cerr<<"zone2sql "<<VERSION<<endl;
+      exit(0);
+    }
   
     if(::arg().mustDo("help")) {
       cout<<"syntax:"<<endl<<endl;
@@ -367,7 +372,7 @@ try
           ++i)
         {
           if(i->type!="master" && i->type!="slave") {
-            cerr<<" Warning! Skipping '"<<i->type<<"' zone '"<<i->name.toString()<<"'"<<endl;
+            cerr<<" Warning! Skipping '"<<i->type<<"' zone '"<<i->name<<"'"<<endl;
             continue;
           }
           try {