Package easyLDAP :: Module easyLDAP_exceptions'
[frames] | no frames]

Source Code for Module easyLDAP.easyLDAP_exceptions'

  1  # -*- coding: utf-8 -*- 
  2   
  3  #    easyLDAP - a python library that makes LDAP management easier than before... 
  4  #    Copyright (C) 2004-2010,2020 Mike Gabriel <m.gabriel@das-netzwerkteam.de> 
  5  # 
  6  #    This program is free software: you can redistribute it and/or modify 
  7  #    it under the terms of the GNU General Public License as published by 
  8  #    the Free Software Foundation, either version 3 of the License, or 
  9  #    (at your option) any later version. 
 10  # 
 11  #    This program is distributed in the hope that it will be useful, 
 12  #    but WITHOUT ANY WARRANTY; without even the implied warranty of 
 13  #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
 14  #    GNU General Public License for more details. 
 15  # 
 16  #    You should have received a copy of the GNU General Public License 
 17  #    along with this program.  If not, see <http://www.gnu.org/licenses/>. 
 18  # 
 19   
 20  from exceptions import Exception 
 21  from easyLDAP_defaults import EASY_LDAP 
 22   
 23  _easyLDAP_base_exceptions = { 
 24                'SERVER_UNAVAILABLE': 'The LDAP server is not available or the specified LDAP URI is invalid.', 
 25                'BINDDN_UNKNOWN': 'Binding to ldap URI failed. Bind DN unknown.', 
 26                'INVALID_CREDENTIALS': 'Binding to ldap URI failed. Invalid credentials.', 
 27                'UID_NOT_FOUND': 'The given UID was not found in the LDAP database', 
 28                'MULTIPLE_DNs_FOR_UID': 'There are multiple DNs for the given UID in the LDAP tree, constrain the search to a subtree with the searchbase paramete or fix your LDAP tree.', 
 29                'NO_SUCH_ATTRIBUTE': 'No such attribute in LDAP schema.', 
 30                'INVALID_ADMIN_CREDENTIALS': 'Administrative access to the ldap server has been denied, check credentials (AdminDN and password).', 
 31                'ACCESS_DENIED': 'Access to the LDAP server has been denied, check credentials (DN and password).', 
 32                'NO_SUCH_OBJECTCLASS': 'No such objectClass in LDAP schema', 
 33                'CN_NOT_FOUND': 'The given CN was not found in the LDAP database.', 
 34                'MULTIPLE_DNs_FOR_CN': 'There are multiple DNs for the given CN in the LDAP tree, constrain the search to a subtree with the searchbase parameter or fix your LDAP tree.', 
 35                'LDAPDATA_MISMATCH': 'The given LDAP object(s) is/are not conformant with the python-ldap data style.', 
 36                'ONLY_ONE_DN_PER_OBJECT': 'Only one DN is accepted per ldap object.', 
 37                'LDAPSCHEMA_NOT_LOADED': 'The server\'s LDAP schema could not be loaded into cache.', 
 38                'LIST_EXPECTED': 'The parameter for this function must be a python list.', 
 39                'UIDNUMBER_RANGE_FAULTY': 'The given uidNumber range is faulty.', 
 40                'GIDNUMBER_RANGE_FAULTY': 'The given gidNumber range is faulty.', 
 41                'NO_VACANT_UIDNUMBER': 'There is no vacant uidNumber in the given range.', 
 42                'NO_VACANT_GIDNUMBER': 'There is no vacant gidNumber in the given range.', 
 43                'UID_LACKS_UIDNUMBER': 'The given uid has been found, but it has no uidNumber attribute set.', 
 44                'MULTIPLE_DNs_FOR_GID': 'There are multiple DNs for the given GID/GIDNUMBER in the LDAP tree, constrain the search to a subtree with the searchbase parameter or fix your LDAP tree', 
 45                'POSIXACCOUNT_OBJECT_LACKS_UIDNUMBER': 'The given UID has been found, but it has no uidNumber attribute set.', 
 46                'NO_SUCH_POSIXGROUP': 'No such GID/GIDNUMBER in LDAP tree.', 
 47                'NO_SUCH_POSIXACCOUNT': 'No such UID/UIDNUMBER in LDAP tree.', 
 48                'NO_SUCH_OU': 'The given OU was not found in the LDAP tree.', 
 49                'MULTIPLE_DNs_FOR_OU': 'There are multiple DNs for the given OU in the LDAP tree.', 
 50                'NO_SUCH_DN_ON_SERVER': 'No such DN in LDAP database.', 
 51                'NO_SUCH_DN_IN_CACHE': 'No such DN in the easyLDAP cache.', 
 52                'INVALID_DN_SYNTAX': 'Invalid DN syntax.', 
 53                'NOT_A_SINGLE_LDAPOBJECT': 'The given data structure is not a single LDAP object (it does contain several DNs).', 
 54                'NOT_A_PYTHON_LDAPOBJECT': 'The given data structure is not a python-like LDAP object.', 
 55                'NOT_AN_LDAPTREE': 'The given data structure does not look like an LDAP (sub)tree.', 
 56                'ATTRTYPE_NOT_SET': 'The specified attribute type ist not used in this LDAP object.', 
 57                'ATTRDESC_NOT_SET': 'The specified attribute description is not used in this LDAP object.', 
 58                'LDAPOBJECTS_EMPTY': 'Both given LDAP objects are empty (no attribute descriptions found).', 
 59                'NO_CHILD_OF_BASEDN': 'The specified DN is not a child of the sessions base DN.', 
 60                'NO_CHILD_OF_ROOTDSE': 'The specified DN is not a child of the sessions base RootDSE.', 
 61                'SAMBA3_ONLY': 'This method is only available with a Samba3 LDAP schema loaded', 
 62  } 
 63  _easyLDAP_cache_exceptions = { 
 64                'UNDO_IMPOSSIBLE': 'Cannot undo anymore.', 
 65                'REDO_IMPOSSIBLE': 'Cannot redo anymore.', 
 66                'CACHEHISTORY_NATURALNUMBER_EXPECTED': 'The given LDAP cache history size must be a natural number.', 
 67                'CACHEOBJECT_IS_SUBTREE': 'The given LDAP cache object has children and cannot be deleted with this method...', 
 68                'NO_SUCH_OBJECT_IN_CACHETREE': 'The given object could not be found in the cachetree.', 
 69                'CACHEHISTORY_INACTIVE': 'The LDAP cache history functionality has been deactived on class object construction (use_cache_history is False).', 
 70  } 
 71  _easyLDAP_object_exceptions = { 
 72                'ATTRIBUTE_NEEDS_OBJECTCLASS': 'Attribute needs an additional objectClass.', 
 73                'TYPE_OR_VALUE_ALREADY_EXISTS': 'The given type or value already exists.', 
 74                'INSUFFICIENT_ACCESS': 'Insufficient access to this object for this operation.', 
 75                'NO_SUCH_ATTRIBUTE_SET': 'No such attribute/OID is set in the easyLDAP object cache.', 
 76                'VALUE_NOT_SET': 'The given value is not set for the given attribute description.', 
 77                'NO_SUCH_OBJECTCLASS_SET': 'No such objectClass is set in the easyLDAP object cache.', 
 78                'INVALID_SYNTAX': 'The ldap server answered with an invalid syntax error.', 
 79                'INVALID_VALUE_SYNTAX': 'The given value does not match the required LDAP syntax definition.', 
 80                'SINGLE_VALUE': 'The attribute has the SINGLE-VALUE flag set. Only one value acceptable.', 
 81                'MISSING_VALUES_IPHOST': 'Hostname and IP number are obligatory for this method.', 
 82                'MISSING_VALUES_SAMBAHOST': 'NETBIOS name, uidNumber, gidNumber and domain-ID are obligatory for this method.', 
 83                'NO_SAMBAOBJECT': 'None of the Samba objectClasses is set in the easyLDAP object cache.', 
 84                'NO_SAMBA_OBJECTCLASS': 'Set one of the available Samba objectClasses (sambaAccount, sambaSamAccount) for this object.', 
 85                'DOMAINSID_IN_SAMBA3_ONLY': 'LDAP servers do only store domain SIDs when using Samba 3.x.', 
 86                'SAMBADOMAIN_DOES_NOT_EXIST_IN_LDAP': 'This Samba3 domain name does not exist in the LDAP tree.', 
 87                'MISSING_OBJECTCLASS_NISMAILALIAS': 'The server\'s LDAP schema needs the objectClass nisMailAlias to perform this operation.', 
 88                'NO_SAMBAACCOUNT_WITHOUT_POSIXACCOUNT': 'To turn this object into a samba user account, you have to make it a posixAccount first.', 
 89                'MISSING_OBJECTCLASS_POSIXACCOUNT': 'No such objectclass posixAccount.', 
 90                'INVALID_DN_PARENT_NISMAPNAME': 'Parent RDN has to be nisMapName=SOMENAME.', 
 91                'DN_NOT_A_CHILD_OF_BASEDN': 'The DN is not a child of the LDAP tree\'s BaseDN.', 
 92                'INVALID_ATTRIBUTETYPE': 'At least one attribute description has an invalid attribute type.', 
 93                'TYPE_OR_INDEX_ERROR': 'There was a type or index error in the method\'s incoming data structure.', 
 94                'SET_ATTRIBUTE_ERROR': 'Not all attribute descriptions could be set in the easyLDAP object cache.', 
 95                'ATTRIBUTE_NOT_A_STRING': 'What you gave me as an attribute type or descriptions does not feel like a string to me...', 
 96                'VALUE_NOT_A_STRING': 'What you gave me as a value does not feel like a string to me...', 
 97                'FAILED_TO_SET_PASSWORD': 'While setting a new password an error occurred...', 
 98                'UNKNOWN_CRYPT_ALGORITHM': 'The specified encryption algorithm is not supported / unknown.', 
 99  } 
100  _easyLDAP_tree_exceptions = { 
101                'NO_PARENTOBJECT_FOR_GIVEN_DN': 'Your object can not be created as it will have no parent object, create the parent object first.', 
102                'ORPHANED_OBJECTS_IN_TREE': 'There are objects in the LDAP cache tree that have no parent, this should not happen...', 
103                'CANNOT_DELETE_BASEDN_OBJECT': 'The LDAP server\'s base DN object cannot be deleted from the LDAP tree, modify its values instead.', 
104  } 
105   
106 -def _easyLDAP_exceptions_generator ():
107 108 exceptions_code = """ 109 110 class easyLDAP_exceptions(): 111 112 def __init__(): 113 return 114 115 """ 116 for key in EASY_LDAP['exceptions'].keys(): 117 exceptions_code +=""" 118 119 class %s (Exception): 120 def __init__(self): 121 return 122 123 def __str__(self): 124 print ":","%s" 125 126 127 """ % (key, EASY_LDAP['exceptions'][key]) 128 129 return exceptions_code
130 131 # by not defining the EASY_LDAP['exceptions'] dictionary directly 132 # we can make sure not to overwrite any predefined exceptions in 133 # easyLDAP_config or anywhere else... 134 for except_dict in [ _easyLDAP_base_exceptions, _easyLDAP_cache_exceptions, _easyLDAP_object_exceptions, _easyLDAP_tree_exceptions ]: 135 for key in except_dict.keys(): 136 EASY_LDAP['exceptions'][key] = except_dict[key] 137 138 # generate the exception classes 139 exec (_easyLDAP_exceptions_generator()) 140 141 if __name__=='__main__': 142 pass 143