[PATCH] b/c dns names can be cased but b/c we didn't handle this to begin with by lower()ing everything I've added a function to return items from our directories case-insensitively with limited globbing support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



---
 func/minion/server.py   |   19 ++++++++++---------
 func/overlord/client.py |   18 +++++++++---------
 func/utils.py           |   29 +++++++++++++++++++++++++----
 3 files changed, 44 insertions(+), 22 deletions(-)

diff --git a/func/minion/server.py b/func/minion/server.py
index 5f217d7..28d6fa1 100644
--- a/func/minion/server.py
+++ b/func/minion/server.py
@@ -29,14 +29,13 @@ from certmaster.commonconfig import CMConfig
 from func import logger
 from certmaster import certs
 import func.jobthing as jobthing
-from func import utils as func_utils
 
 # our modules
 import AuthedXMLRPCServer
 import codes
 import func.module_loader as module_loader
 import func.minion.acls as acls_mod
-from func import utils as futils
+from func import utils as func_utils
 
 
 from certmaster import utils
@@ -89,6 +88,8 @@ class XmlRpcInterface(object):
         self.handlers["system.list_modules"] = self.list_modules
         self.handlers["system.inventory"] = self.inventory
         self.handlers["system.grep"] = self.grep
+        # ultimately need to add a method here to force the server to reload itself so all NEW connections
+        # get a new RequestHandler
 
     def list_modules(self):
         modules = self.modules.keys()
@@ -100,9 +101,6 @@ class XmlRpcInterface(object):
         methods.sort()
         return methods
     
-    def load_module(self, name):
-        """FIXME load a module and set it up on the running xmlrpc instance"""
-        pass
     
     import func.minion.modules.func_module as fm
     def grep(self,word):
@@ -192,7 +190,7 @@ class FuncApiMethod:
         self.logger.debug("(X) -------------------------------------------")
 
         try:
-            self.__method = futils.get_fresh_method_instance(self.__method)
+            self.__method = func_utils.get_fresh_method_instance(self.__method)
             rc = self.__method(*args)
         except codes.FuncException, e:
             self.__log_exc()
@@ -250,12 +248,15 @@ class FuncSSLXMLRPCServer(AuthedXMLRPCServer.AuthedSSLXMLRPCServer,
         if self.config.key_file != '':
             self.key = self.config.key_file
         else:
-            self.key = "%s/%s.pem" % (self.cm_config.cert_dir, hn)            
+            # search case-insensitively to find the right key - take the first one - if there are
+            # more than one differing only by case then the user is going to get 'unique' behavior :)
+            self.key = func_utils.find_files_by_hostname(hn, self.cm_config.cert_dir, '.pem')[0]
         
         if self.config.cert_file != '':
             self.cert = self.config.cert_file
         else:
-            self.cert = "%s/%s.cert" % (self.cm_config.cert_dir, hn)
+            self.cert = func_utils.find_files_by_hostname(hn, self.cm_config.cert_dir, '.cert')[0]
+
         if self.config.ca_file != '':
             self.ca = self.config.ca_file
         else:
@@ -373,7 +374,7 @@ def main(argv):
     try:
         config = read_config("/etc/func/minion.conf", FuncdConfig)
         if config.use_certmaster:
-            hn = futils.get_hostname_by_route()
+            hn = func_utils.get_hostname_by_route()
             requester.request_cert(hn)
         serve()
     except codes.FuncException, e:
diff --git a/func/overlord/client.py b/func/overlord/client.py
index 0931172..12deb49 100644
--- a/func/overlord/client.py
+++ b/func/overlord/client.py
@@ -15,7 +15,6 @@
 from func.jobthing import RETAIN_INTERVAL
 
 import sys
-import glob
 import os
 import time
 import shlex
@@ -158,13 +157,14 @@ class Minions(object):
             else:
                 each_gloob = shortest_path[0]
 
-        actual_gloob = "%s/%s.%s" % (self.cm_config.certroot, each_gloob, self.cm_config.cert_extension)
-        certs = glob.glob(actual_gloob)
+        #actual_gloob = "%s/%s.%s" % (self.cm_config.certroot, each_gloob, self.cm_config.cert_extension)
+        certs = func_utils.find_files_by_hostname(each_gloob, self.cm_config.certroot, self.cm_config.cert_extension)
         
         # pull in peers if enabled for minion-to-minion
         if self.cm_config.peering:
-            peer_gloob = "%s/%s.%s" % (self.cm_config.peerroot, each_gloob, self.cm_config.cert_extension)
-            certs += glob.glob(peer_gloob)
+            #peer_gloob = "%s/%s.%s" % (self.cm_config.peerroot, each_gloob, self.cm_config.cert_extension)
+            certs += func_utils.find_files_by_hostname(each_gloob, self.cm_config.peeroot, self.cm_config.cert_extension)            
+            
         
         # if we can't match this gloob and the gloob is not REALLY a glob
         # let the gloob be the hostname we try to connect to.
@@ -173,11 +173,11 @@ class Minions(object):
             aliases = func_utils.get_all_host_aliases(each_gloob)
 
             for name in aliases:
-                actual_gloob = "%s/%s.%s" % (self.cm_config.certroot, name, self.cm_config.cert_extension)
-                certs += glob.glob(actual_gloob)
+                #actual_gloob = "%s/%s.%s" % (self.cm_config.certroot, name, self.cm_config.cert_extension)
+                certs += func_utils.find_files_by_hostname(name, self.cm_config.certroot, self.cm_config.cert_extension)                
                 if self.cm_config.peering:
-                    peer_gloob = "%s/%s.%s" % (self.cm_config.peerroot, name, self.cm_config.cert_extension)
-                    certs += glob.glob(peer_gloob)
+                    #peer_gloob = "%s/%s.%s" % (self.cm_config.peerroot, name, self.cm_config.cert_extension)
+                    certs += func_utils.find_files_by_hostname(name, self.cm_config.peeroot, self.cm_config.cert_extension)
                     break
 
             if self.overlord_config.allow_unknown_minions and not certs:
diff --git a/func/utils.py b/func/utils.py
index fcc5cdc..fe0c9da 100644
--- a/func/utils.py
+++ b/func/utils.py
@@ -16,6 +16,7 @@ import socket
 import string
 import sys
 import re
+import fnmatch
 
 from certmaster.config import read_config
 from certmaster.commonconfig import MinionConfig
@@ -86,7 +87,7 @@ def get_hostname_by_route():
 
     # don't bother guessing a hostname if they specify it in the config file
     if minion_config.minion_name:
-        return minion_config.minion_name
+        return minion_config.minion_name.lower()
 
     # try to find the hostname attached to the ip of the interface that we use
     # to talk to the certmaster
@@ -107,7 +108,7 @@ def get_hostname_by_route():
         # not talking via localhost? good enough...
         if ip != '127.0.0.1':
             s.close()
-            return intf_hostname
+            return intf_hostname.lower()
     except:
         s.close()
         # something failed, reverse dns, etc
@@ -133,13 +134,33 @@ def get_hostname_by_route():
 
     # non loopback is about as good as we can do for a guess
     if ip != "127.0.0.1" and hostname is not None:
-        return hostname
+        return hostname.lower()
             
   
 
     # all else has failed to get a good hostname, so just return
     # an ip address
-    return socket.gethostbyname(socket.gethostname())
+    return socket.gethostbyname(socket.gethostname()).lower() # yes I know it's an ip but I don't trust anything
+
+def find_files_by_hostname(hostglob, filepath, fileext=''):
+    """look for files in the given filepath with the given extension that
+        match our hostname, but case insensitively. This handles the 
+        craziness that is dns names that have mixed case :("""
+    
+    # this is a little like a case insensitive glob, except it's just one 
+    # layer deep - not multiple layers
+    
+    if fileext and fileext[0] != '.':
+        fileext = '.' + fileext
+    thisregex = fnmatch.translate('%s%s' % (hostglob, fileext)) 
+    recomp = re.compile(thisregex, re.I) # case insensitive match
+    files = []
+    for potfile in os.listdir(filepath):
+        if recomp.match(potfile):
+            files.append(potfile)
+    
+    return [os.path.normpath(filepath + '/' + file) for file in files]
+
 
 def get_all_host_aliases(hostname):
     try:
-- 
1.7.2

_______________________________________________
Func-list mailing list
Func-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/func-list


[Index of Archives]     [Fedora Users]     [Linux Networking]     [Fedora Legacy List]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]

  Powered by Linux