You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

82 lines
2.9 KiB

  1. #-*- coding: utf-8 -*-
  2. # Copyright 2008-2010 Mir Calculate Ltd. http://www.calculate-linux.org
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. import os
  16. from cl_datavars import glob_attr
  17. from cl_utils import genpassword
  18. from encrypt import encrypt
  19. class fillVars(glob_attr):
  20. encryptObj = encrypt()
  21. addDn = lambda x,*y: ",".join(y)
  22. genDn = lambda x,*y: "=".join(y)
  23. def getHash(self, password, encrypt):
  24. """Получить хеш пароля
  25. password - пароль
  26. encrypt - алгоритм шифрования, например 'ssha'
  27. """
  28. hashPwd = self.encryptObj.getHashPasswd(password, encrypt.lower())
  29. if hashPwd:
  30. return hashPwd
  31. else:
  32. print "Error encrypt password, method getHash()"
  33. exit(1)
  34. def get_ld_base_dn(self):
  35. """базовый DN LDAP"""
  36. return self.genDn("dc", self.Get('ld_base_root'))
  37. def get_ld_bind_dn(self):
  38. """bind DN LDAP"""
  39. return self.addDn(self.genDn("cn", self.Get('ld_bind_login')),
  40. self.Get('ld_base_dn'))
  41. def get_ld_bind_hash(self):
  42. """hash пароля для пользователя для чтения"""
  43. return self.getHash(self.Get('ld_bind_pw'), self.Get('ld_encrypt'))
  44. def get_ld_temp_dn(self):
  45. #DN временного пользователя root (для инициализации базы данных)
  46. return self.addDn(self.genDn("cn", "ldaproot"), self.Get('ld_base_dn'))
  47. def get_ld_temp_pw(self):
  48. """пароль временного пользователя root"""
  49. return genpassword()
  50. def get_ld_temp_hash(self):
  51. """hash пароля временного root"""
  52. return self.getHash(self.Get('ld_temp_pw'), self.Get('ld_encrypt'))
  53. def get_ld_admin_dn(self):
  54. """DN пользователя root"""
  55. return self.addDn(self.genDn("cn", self.Get('ld_admin_login')),
  56. self.Get('ld_base_dn'))
  57. def get_ld_admin_hash(self):
  58. """hash пароля root"""
  59. return self.getHash(self.Get('ld_admin_pw'), self.Get('ld_encrypt'))
  60. def get_ld_admin_pw(self):
  61. """пароль root"""
  62. return genpassword()
  63. def get_ld_services_dn(self):
  64. """DN для всех сервисов"""
  65. return self.addDn(self.genDn("ou", self.Get('ld_services')),
  66. self.Get('ld_base_dn'))