Class | LDAP::Schema2 |
In: |
lib/activeldap/schema2.rb
|
Parent: | Schema |
attr
This is just like LDAP::Schema#attr except that it allows look up in any of the given keys. e.g.
attr('attributeTypes', 'cn', 'DESC') attr('ldapSyntaxes', '1.3.6.1.4.1.1466.115.121.1.5', 'DESC')
# File lib/activeldap/schema2.rb, line 16 16: def attr(sub, type, at) 17: return [] if sub.empty? 18: return [] if type.empty? 19: return [] if at.empty? 20: 21: type = type.downcase # We're going case insensitive. 22: 23: # Check already parsed options first 24: if @@attr_cache.has_key? sub \ 25: and @@attr_cache[sub].has_key? type \ 26: and @@attr_cache[sub][type].has_key? at 27: return @@attr_cache[sub][type][at].dup 28: end 29: 30: # Initialize anything that is required 31: unless @@attr_cache.has_key? sub 32: @@attr_cache[sub] = {} 33: end 34: 35: unless @@attr_cache[sub].has_key? type 36: @@attr_cache[sub][type] = {} 37: end 38: 39: at = at.upcase 40: self[sub].each do |s| 41: line = '' 42: if type[0..0] =~ /[0-9]/ 43: if s =~ /\(\s+(?i:#{type})\s+(?:[A-Z]|\))/ 44: line = s 45: end 46: else 47: if s =~ /NAME\s+\(?.*'(?i:#{type})'.*\)?\s+(?:[A-Z]|\))/ 48: line = s 49: end 50: end 51: 52: # I need to check, but I think some of these matchs 53: # overlap. I'll need to check these when I'm less sleepy. 54: multi = '' 55: case line 56: when /#{at}\s+[\)A-Z]/ 57: @@attr_cache[sub][type][at] = ['TRUE'] 58: return ['TRUE'] 59: when /#{at}\s+'(.+?)'/ 60: @@attr_cache[sub][type][at] = [$1] 61: return [$1] 62: when /#{at}\s+\((.+?)\)/ 63: multi = $1 64: when /#{at}\s+\(([\w\d\s\.]+)\)/ 65: multi = $1 66: when /#{at}\s+([\w\d\.]+)/ 67: @@attr_cache[sub][type][at] = [$1] 68: return [$1] 69: end 70: # Split up multiple matches 71: # if oc then it is sep'd by $ 72: # if attr then bu spaces 73: if multi.match(/\$/) 74: @@attr_cache[sub][type][at] = multi.split("$").collect{|attr| attr.strip} 75: return @@attr_cache[sub][type][at].dup 76: elsif not multi.empty? 77: @@attr_cache[sub][type][at] = multi.gsub(/'/, '').split(' ').collect{|attr| attr.strip} 78: return @@attr_cache[sub][type][at].dup 79: end 80: end 81: @@attr_cache[sub][type][at] = [] 82: return [] 83: end
Returns all names from the LDAP schema for the attribute given.
# File lib/activeldap/schema2.rb, line 89 89: def attribute_aliases(attr) 90: attr('attributeTypes', attr, 'NAME') 91: end
binary?
Returns true if the given attribute’s syntax is X-NOT-HUMAN-READABLE or X-BINARY-TRANSFER-REQUIRED
# File lib/activeldap/schema2.rb, line 118 118: def binary?(attr) 119: # Get syntax OID 120: syntax = attr('attributeTypes', attr, 'SYNTAX') 121: return false if syntax.empty? 122: 123: # This seems to indicate binary 124: result = attr('ldapSyntaxes', syntax[0], 'X-NOT-HUMAN-READABLE') 125: return true if result[0] == "TRUE" 126: 127: # Get if binary transfer is required (non-binary types) 128: # Usually these have the above tag 129: result = attr('ldapSyntaxes', syntax[0], 'X-BINARY-TRANSFER-REQUIRED') 130: return true if result[0] == "TRUE" 131: 132: return false 133: end
Returns true if the value MUST be transferred in binary
# File lib/activeldap/schema2.rb, line 138 138: def binary_required?(attr) 139: # Get syntax OID 140: syntax = attr('attributeTypes', attr, 'SYNTAX') 141: return false if syntax.empty? 142: 143: # Get if binary transfer is required (non-binary types) 144: # Usually these have the above tag 145: result = attr('ldapSyntaxes', syntax[0], 'X-BINARY-TRANSFER-REQUIRED') 146: return true if result[0] == "TRUE" 147: 148: return false 149: end
Returns an Array of all the valid attributes (but not with full aliases) for the given objectClass
# File lib/activeldap/schema2.rb, line 155 155: def class_attributes(objc) 156: if @@class_cache.has_key? objc 157: return @@class_cache[objc] 158: end 159: 160: # Setup the cache 161: @@class_cache[objc] = {} 162: 163: # First get all the current level attributes 164: @@class_cache[objc] = {:must => attr('objectClasses', objc, 'MUST'), 165: :may => attr('objectClasses', objc, 'MAY')} 166: 167: # Now add all attributes from the parent object (SUPerclasses) 168: # Hopefully an iterative approach will be pretty speedy 169: # 1. build complete list of SUPs 170: # 2. Add attributes from each 171: sups = attr('objectClasses', objc, 'SUP') 172: loop do 173: start_size = sups.size 174: new_sups = [] 175: sups.each do |sup| 176: new_sups += attr('objectClasses', sup, 'SUP') 177: end 178: 179: sups += new_sups 180: sups.uniq! 181: break if sups.size == start_size 182: end 183: sups.each do |sup| 184: @@class_cache[objc][:must] += attr('objectClasses', sup, 'MUST') 185: @@class_cache[objc][:may] += attr('objectClasses', sup, 'MAY') 186: end 187: 188: # Clean out the dupes. 189: @@class_cache[objc][:must].uniq! 190: @@class_cache[objc][:may].uniq! 191: 192: # Return the cached value 193: return @@class_cache[objc].dup 194: end
Returns true if an attribute is read-only NO-USER-MODIFICATION
# File lib/activeldap/schema2.rb, line 97 97: def read_only?(attr) 98: result = attr('attributeTypes', attr, 'NO-USER-MODIFICATION') 99: return true if result[0] == 'TRUE' 100: return false 101: end