tsig_keys.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2011 Internet Systems Consortium.
  2. #
  3. # Permission to use, copy, modify, and distribute this software for any
  4. # purpose with or without fee is hereby granted, provided that the above
  5. # copyright notice and this permission notice appear in all copies.
  6. #
  7. # THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SYSTEMS CONSORTIUM
  8. # DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
  9. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
  10. # INTERNET SYSTEMS CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT,
  11. # INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
  12. # FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
  13. # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
  14. # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. from isc.config.module_spec import module_spec_from_file
  16. from isc.util.file import path_search
  17. from pydnspp import TSIGKey, InvalidParameter
  18. from bind10_config import PLUGIN_PATHS
  19. spec = module_spec_from_file(path_search('tsig_keys.spec', PLUGIN_PATHS))
  20. def check(config):
  21. # Check the data layout first
  22. errors=[]
  23. if not spec.validate_config(False, config, errors):
  24. return ' '.join(errors)
  25. # Get the list of keys, if any
  26. keys = config.get('keys', [])
  27. # Run trough them, check they can be constructed and there are no dupes
  28. keyNames = set()
  29. for key in keys:
  30. try:
  31. name = str(TSIGKey(key).get_key_name())
  32. except InvalidParameter as e:
  33. return "TSIG: " + str(e)
  34. if name in keyNames:
  35. return "Multiple TSIG keys with name '" + name + "'"
  36. keyNames.add(name)
  37. # No error found, so let's assume it's OK
  38. return None
  39. def load():
  40. return (spec, check)