]> git.ipfire.org Git - thirdparty/pdns.git/blobdiff - pdns/arguments.cc
rec: ensure correct service user on debian
[thirdparty/pdns.git] / pdns / arguments.cc
index 491e018b80b1eff470bc31dde4e901c3a96bdce9..1f2d04456a0c2609a38c26fdd84887594bcb88b8 100644 (file)
@@ -97,11 +97,10 @@ bool ArgvMap::contains(const string &var, const string &val)
     return false;
   }
   vector<string> parts;
-  vector<string>::const_iterator i;
   
   stringtok( parts, param->second, ", \t" );
-  for( i = parts.begin(); i != parts.end(); i++ ) {
-    if( *i == val ) {
+  for (const auto& part: parts) {
+    if (part == val) {
       return true;
     }
   }
@@ -115,30 +114,27 @@ string ArgvMap::helpstring(string prefix)
     prefix="";
   
   string help;
-  
-  for(map<string,string>::const_iterator i=helpmap.begin();
-      i!=helpmap.end();
-      i++)
-    {
-      if(!prefix.empty() && i->first.find(prefix)) // only print items with prefix
-        continue;
+
+  for (const auto& i: helpmap) {
+      if(!prefix.empty() && i.first.find(prefix) != 0) // only print items with prefix
+          continue;
 
       help+="  --";
-      help+=i->first;
+      help+=i.first;
       
-      string type=d_typeMap[i->first];
+      string type=d_typeMap[i.first];
 
       if(type=="Parameter")
         help+="=...";
       else if(type=="Switch")
         {
-          help+=" | --"+i->first+"=yes";
-          help+=" | --"+i->first+"=no";
+          help+=" | --"+i.first+"=yes";
+          help+=" | --"+i.first+"=no";
         }
       
 
       help+="\n\t";
-      help+=i->second;
+      help+=i.second;
       help+="\n";
 
     }
@@ -154,20 +150,20 @@ string ArgvMap::configstring(bool current)
   else
     help="# Autogenerated configuration file template\n";
   
-  for(map<string,string>::const_iterator i=helpmap.begin(); i!=helpmap.end(); i++) {
-    if(d_typeMap[i->first]=="Command")
+  for(const auto& i: helpmap) {
+    if(d_typeMap[i.first]=="Command")
       continue;
 
     help+="#################################\n";
     help+="# ";
-    help+=i->first;
+    help+=i.first;
     help+="\t";
-    help+=i->second;
+    help+=i.second;
     help+="\n#\n";
     if (current) {
-      help+=i->first+"="+params[i->first]+"\n\n";
+      help+=i.first+"="+params[i.first]+"\n\n";
     } else {
-      help+="# "+i->first+"="+params[i->first]+"\n\n";
+      help+="# "+i.first+"="+params[i.first]+"\n\n";
     }
   }
   return help;
@@ -304,18 +300,18 @@ void ArgvMap::parseOne(const string &arg, const string &parseOnly, bool lax)
   string::size_type pos;
   bool incremental = false;
 
-  if(!arg.find("--") && (pos=arg.find("+="))!=string::npos) // this is a --port+=25 case
+  if(arg.find("--") == 0 && (pos=arg.find("+="))!=string::npos) // this is a --port+=25 case
   {
     var=arg.substr(2,pos-2);
     val=arg.substr(pos+2);
     incremental = true;
   }
-  else if(!arg.find("--") && (pos=arg.find("="))!=string::npos)  // this is a --port=25 case
+  else if(arg.find("--") == 0 && (pos=arg.find("="))!=string::npos)  // this is a --port=25 case
   {
     var=arg.substr(2,pos-2);
     val=arg.substr(pos+1);
   }
-  else if(!arg.find("--") && (arg.find("=")==string::npos))  // this is a --daemon case
+  else if(arg.find("--") == 0 && (arg.find("=")==string::npos))  // this is a --daemon case
   {
     var=arg.substr(2);
     val="";
@@ -376,7 +372,7 @@ void ArgvMap::preParse(int &argc, char **argv, const string &arg)
 {
   for(int n=1;n<argc;n++) {
     string varval=argv[n];
-    if(!varval.find("--"+arg))
+    if(varval.find("--"+arg) == 0)
       parseOne(argv[n]);
   }
 }
@@ -443,7 +439,7 @@ bool ArgvMap::file(const char *fname, bool lax, bool included)
     set("include-dir","Directory to include configuration files from");
 
   if(!parseFile(fname, "", lax)) {
-    L << Logger::Warning << "Unable to open " << fname << std::endl;
+    g_log << Logger::Warning << "Unable to open " << fname << std::endl;
     return false;
   }
 
@@ -453,7 +449,7 @@ bool ArgvMap::file(const char *fname, bool lax, bool included)
     gatherIncludes(extraConfigs); 
     for(const std::string& fn :  extraConfigs) {
       if (!file(fn.c_str(), lax, true)) {
-        L << Logger::Error << fn << " could not be parsed" << std::endl;
+        g_log << Logger::Error << fn << " could not be parsed" << std::endl;
         throw ArgException(fn + " could not be parsed");
       }
     }
@@ -471,18 +467,18 @@ void ArgvMap::gatherIncludes(std::vector<std::string> &extraConfigs) {
 
     // stat
     if (stat(params["include-dir"].c_str(), &st)) {
-       L << Logger::Error << params["include-dir"] << " does not exist!" << std::endl;
+       g_log << Logger::Error << params["include-dir"] << " does not exist!" << std::endl;
        throw ArgException(params["include-dir"] + " does not exist!");
     }
 
     // wonder if it's accessible directory
     if (!S_ISDIR(st.st_mode)) {
-       L << Logger::Error << params["include-dir"] << " is not a directory" << std::endl;
+       g_log << Logger::Error << params["include-dir"] << " is not a directory" << std::endl;
        throw ArgException(params["include-dir"] + " is not a directory");
     }
 
     if (!(dir = opendir(params["include-dir"].c_str()))) {
-       L << Logger::Error << params["include-dir"] << " is not accessible" << std::endl;
+       g_log << Logger::Error << params["include-dir"] << " is not accessible" << std::endl;
        throw ArgException(params["include-dir"] + " is not accessible");
     }
 
@@ -494,7 +490,8 @@ void ArgvMap::gatherIncludes(std::vector<std::string> &extraConfigs) {
         namebuf << params["include-dir"].c_str() << "/" << ent->d_name; // FIXME: Use some path separator
         // ensure it's readable file
         if (stat(namebuf.str().c_str(), &st) || !S_ISREG(st.st_mode)) {
-          L << Logger::Error << namebuf.str() << " is not a file" << std::endl;
+          g_log << Logger::Error << namebuf.str() << " is not a file" << std::endl;
+          closedir(dir);
           throw ArgException(namebuf.str() + " does not exist!");
         }
         extraConfigs.push_back(namebuf.str());