]> granicus.if.org Git - pdns/commitdiff
Use proper conversions on GeoIP backend
authorAki Tuomi <cmouse@desteem.org>
Fri, 11 Dec 2015 14:42:43 +0000 (16:42 +0200)
committerAki Tuomi <cmouse@desteem.org>
Mon, 21 Dec 2015 12:52:00 +0000 (14:52 +0200)
modules/geoipbackend/geoipbackend.cc

index 2ccd7fe9de7613147039c634594abf02e20b832f..94c1fdce820dc387741585125d11286d471f53e4 100644 (file)
@@ -725,9 +725,9 @@ bool GeoIPBackend::getDomainKeys(const DNSName& name, unsigned int kind, std::ve
         for(size_t i=0;i<glob_result.gl_pathc;i++) {
           if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
             DNSBackend::KeyData kd;
-            kd.id = atoi(glob_result.gl_pathv[i]+regm[3].rm_so);
-            kd.active = atoi(glob_result.gl_pathv[i]+regm[4].rm_so);
-            kd.flags = atoi(glob_result.gl_pathv[i]+regm[2].rm_so);
+            kd.id = pdns_stou(glob_result.gl_pathv[i]+regm[3].rm_so);
+            kd.active = !strncmp(glob_result.gl_pathv[i]+regm[4].rm_so, "1", 1);
+            kd.flags = pdns_stou(glob_result.gl_pathv[i]+regm[2].rm_so);
             ifstream ifs(glob_result.gl_pathv[i]);
             ostringstream content;
             char buffer[1024];
@@ -767,7 +767,7 @@ bool GeoIPBackend::removeDomainKey(const DNSName& name, unsigned int id) {
       if (glob(pathname.str().c_str(),GLOB_ERR,NULL,&glob_result) == 0) {
         for(size_t i=0;i<glob_result.gl_pathc;i++) {
           if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
-            unsigned int kid = atoi(glob_result.gl_pathv[i]+regm[3].rm_so);
+            unsigned int kid = pdns_stou(glob_result.gl_pathv[i]+regm[3].rm_so);
             if (kid == id) {
               if (unlink(glob_result.gl_pathv[i])) {
                 cerr << "Cannot delete key:" << strerror(errno) << endl;
@@ -788,7 +788,7 @@ bool GeoIPBackend::removeDomainKey(const DNSName& name, unsigned int id) {
 int GeoIPBackend::addDomainKey(const DNSName& name, const KeyData& key) {
   if (!d_dnssec) return false;
   WriteLock rl(&s_state_lock);
-  int nextid=1;
+  unsigned int nextid=1;
 
   for(GeoIPDomain dom :  s_domains) {
     if (dom.domain == name) {
@@ -801,7 +801,7 @@ int GeoIPBackend::addDomainKey(const DNSName& name, const KeyData& key) {
       if (glob(pathname.str().c_str(),GLOB_ERR,NULL,&glob_result) == 0) {
         for(size_t i=0;i<glob_result.gl_pathc;i++) {
           if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
-            int kid = atoi(glob_result.gl_pathv[i]+regm[3].rm_so);
+            unsigned int kid = pdns_stou(glob_result.gl_pathv[i]+regm[3].rm_so);
             if (kid >= nextid) nextid = kid+1;
           }
         }
@@ -834,10 +834,10 @@ bool GeoIPBackend::activateDomainKey(const DNSName& name, unsigned int id) {
       if (glob(pathname.str().c_str(),GLOB_ERR,NULL,&glob_result) == 0) {
         for(size_t i=0;i<glob_result.gl_pathc;i++) {
           if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
-            unsigned int kid = atoi(glob_result.gl_pathv[i]+regm[3].rm_so);
-            if (kid == id && atoi(glob_result.gl_pathv[i]+regm[4].rm_so) == 0) {
+            unsigned int kid = pdns_stou(glob_result.gl_pathv[i]+regm[3].rm_so);
+            if (kid == id && !strcmp(glob_result.gl_pathv[i]+regm[4].rm_so,"0")) {
               ostringstream newpath; 
-              newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << atoi(glob_result.gl_pathv[i]+regm[2].rm_so) << "." << kid << ".1.key";
+              newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << pdns_stou(glob_result.gl_pathv[i]+regm[2].rm_so) << "." << kid << ".1.key";
               if (rename(glob_result.gl_pathv[i], newpath.str().c_str())) {
                 cerr << "Cannot active key: " << strerror(errno) << endl;
               }
@@ -867,10 +867,10 @@ bool GeoIPBackend::deactivateDomainKey(const DNSName& name, unsigned int id) {
       if (glob(pathname.str().c_str(),GLOB_ERR,NULL,&glob_result) == 0) {
         for(size_t i=0;i<glob_result.gl_pathc;i++) {
           if (regexec(&reg, glob_result.gl_pathv[i], 5, regm, 0) == 0) {
-            unsigned int kid = atoi(glob_result.gl_pathv[i]+regm[3].rm_so);
-            if (kid == id && atoi(glob_result.gl_pathv[i]+regm[4].rm_so) == 1) {
+            unsigned int kid = pdns_stou(glob_result.gl_pathv[i]+regm[3].rm_so);
+            if (kid == id && !strcmp(glob_result.gl_pathv[i]+regm[4].rm_so,"1")) {
               ostringstream newpath;
-              newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << atoi(glob_result.gl_pathv[i]+regm[2].rm_so) << "." << kid << ".0.key";
+              newpath << getArg("dnssec-keydir") << "/" << dom.domain.toStringNoDot() << "." << pdns_stou(glob_result.gl_pathv[i]+regm[2].rm_so) << "." << kid << ".0.key";
               if (rename(glob_result.gl_pathv[i], newpath.str().c_str())) {
                 cerr << "Cannot deactive key: " << strerror(errno) << endl;
               }