datacom_active_directory 1.5.5.datacom

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,35 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ class Computer < Base
23
+ def self.filter # :nodoc:
24
+ Net::LDAP::Filter.eq(:objectClass,'computer')
25
+ end
26
+
27
+ def self.required_attributes # :nodoc:
28
+ { :objectClass => [ 'top', 'person', 'organizationalPerson', 'user', 'computer' ] }
29
+ end
30
+
31
+ def hostname
32
+ dNSHostName || name
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,114 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ #
23
+ # The ActiveDirectory::Container class represents a more malleable way
24
+ # of dealing with LDAP Distinguished Names (dn), like
25
+ # "cn=UserName,ou=Users,dc=example,dc=org".
26
+ #
27
+ # The following two representations of the above dn are identical:
28
+ #
29
+ # dn = "cn=UserName,ou=Users,dc=example,dc=org"
30
+ # dn = ActiveDirectory::Container.dc('org').dc('example').ou('Users').cn('UserName').to_s
31
+ #
32
+ class Container
33
+ attr_reader :type
34
+ attr_reader :name
35
+ attr_reader :parent
36
+
37
+ def initialize(type, name, node = nil) #:nodoc:
38
+ @type = type
39
+ @name = name
40
+ @node = node
41
+ end
42
+
43
+ #
44
+ # Creates a starting OU (Organizational Unit) dn part.
45
+ #
46
+ # # ou_part = "ou=OrganizationalUnit"
47
+ # ou_part = ActiveDirectory::Container.ou('OrganizationalUnit').to_s
48
+ #
49
+ def self.ou(name)
50
+ new(:ou, name, nil)
51
+ end
52
+
53
+ #
54
+ # Creates a starting DC (Domain Component) dn part.
55
+ #
56
+ # # dc_part = "dc=net"
57
+ # dc_part = ActiveDirectory::Container.dc('net').to_s
58
+ #
59
+ def self.dc(name)
60
+ new(:dc, name, nil)
61
+ end
62
+
63
+ #
64
+ # Creates a starting CN (Canonical Name) dn part.
65
+ #
66
+ # # cn_part = "cn=CanonicalName"
67
+ # cn_part = ActiveDirectory::Container.cn('CanonicalName').to_s
68
+ #
69
+ def self.cn(name)
70
+ new(:cn, name, nil)
71
+ end
72
+
73
+ #
74
+ # Appends an OU (Organizational Unit) dn part to another Container.
75
+ #
76
+ # # ou = "ou=InfoTech,dc=net"
77
+ # ou = ActiveDirectory::Container.dc("net").ou("InfoTech").to_s
78
+ #
79
+ def ou(name)
80
+ self.class.new(:ou, name, self)
81
+ end
82
+
83
+ #
84
+ # Appends a DC (Domain Component) dn part to another Container.
85
+ #
86
+ # # base = "dc=example,dc=net"
87
+ # base = ActiveDirectory::Container.dc("net").dc("example").to_s
88
+ #
89
+ def dc(name)
90
+ self.class.new(:dc, name, self)
91
+ end
92
+
93
+ #
94
+ # Appends a CN (Canonical Name) dn part to another Container.
95
+ #
96
+ # # user = "cn=UID,ou=Users"
97
+ # user = ActiveDirectory::Container.ou("Users").cn("UID")
98
+ #
99
+ def cn(name)
100
+ self.class.new(:cn, name, self)
101
+ end
102
+
103
+ #
104
+ # Converts the Container object to its String representation.
105
+ #
106
+ def to_s
107
+ @node ? "#{@type}=#{name},#{@node.to_s}" : "#{@type}=#{name}"
108
+ end
109
+
110
+ def ==(other) #:nodoc:
111
+ to_s.downcase == other.to_s.downcase
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,39 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class Binary
24
+ #
25
+ # Encodes a hex string into a GUID
26
+ #
27
+ def self.encode(hex_string)
28
+ [hex_string].pack("H*")
29
+ end
30
+
31
+ #
32
+ # Decodes a binary GUID as a hex string
33
+ #
34
+ def self.decode(guid)
35
+ guid.unpack("H*").first.to_s
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,39 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class Date
24
+ #
25
+ # Converts a time object into an ISO8601 format compatable with Active Directory
26
+ #
27
+ def self.encode(local_time)
28
+ local_time.strftime('%Y%m%d%H%M%S.0Z')
29
+ end
30
+
31
+ #
32
+ # Decodes an Active Directory date when stored as ISO8601
33
+ #
34
+ def self.decode(remote_time)
35
+ Time.parse(remote_time)
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,40 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class DnArray
24
+ #
25
+ # Encodes an array of objects into a list of dns
26
+ #
27
+ def self.encode(obj_array)
28
+ obj_array.collect { |obj| obj.dn }
29
+ end
30
+
31
+ #
32
+ # Decodes a list of DNs into the objects that they are
33
+ #
34
+ def self.decode(dn_array)
35
+ # How to do user or group?
36
+ Base.find(:all, :distinguishedname => dn_array)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class GroupDnArray
24
+ #
25
+ # Encodes an array of objects into a list of dns
26
+ #
27
+ def self.encode(obj_array)
28
+ obj_array.collect { |obj| obj.dn }
29
+ end
30
+
31
+ #
32
+ # Decodes a list of DNs into the objects that they are
33
+ #
34
+ def self.decode(dn_array)
35
+ # How to do user or group?
36
+ Group.find(:all, :distinguishedname => dn_array)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,47 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class MemberDnArray
24
+ #
25
+ # Encodes an array of objects into a list of dns
26
+ #
27
+ def self.encode(obj_array)
28
+ obj_array.collect { |obj| obj.dn }
29
+ end
30
+
31
+ #
32
+ # Decodes a list of DNs into the objects that they are
33
+ #
34
+ def self.decode(dn_array)
35
+ # Ensures that the objects are cast correctly
36
+ users = User.find(:all, :distinguishedname => dn_array)
37
+ groups = Group.find(:all, :distinguishedname => dn_array)
38
+
39
+ arr = Array.new
40
+ arr << users unless users.nil?
41
+ arr << groups unless groups.nil?
42
+
43
+ return arr.flatten
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,41 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class Password
24
+ #
25
+ # Encodes an unencrypted password into an encrypted password
26
+ # that the Active Directory server will understand.
27
+ #
28
+ def self.encode(password)
29
+ ("\"#{password}\"".split(//).collect { |c| "#{c}\000" }).join
30
+ end
31
+
32
+ #
33
+ # Always returns nil, since you can't decrypt the User's encrypted
34
+ # password.
35
+ #
36
+ def self.decode(hashed)
37
+ nil
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,45 @@
1
+ #-- license
2
+ #
3
+ # Based on original code by Justin Mecham and James Hunt
4
+ # at http://rubyforge.org/projects/activedirectory
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
+ #++ license
20
+
21
+ module ActiveDirectory
22
+ module FieldType
23
+ class Timestamp
24
+ AD_DIVISOR = 10_000_000 #:nodoc:
25
+ AD_OFFSET = 11_644_473_600 #:nodoc:
26
+
27
+ #
28
+ # Encodes a local Time object (or the number of seconds since January
29
+ # 1, 1970) into a timestamp that the Active Directory server can
30
+ # understand (number of 100 nanosecond time units since January 1, 1600)
31
+ #
32
+ def self.encode(local_time)
33
+ (local_time.to_i + AD_OFFSET) * AD_DIVISOR
34
+ end
35
+
36
+ #
37
+ # Decodes an Active Directory timestamp (the number of 100 nanosecond time
38
+ # units since January 1, 1600) into a Ruby Time object.
39
+ #
40
+ def self.decode(remote_time)
41
+ Time.at( (remote_time.to_i / AD_DIVISOR) - AD_OFFSET )
42
+ end
43
+ end
44
+ end
45
+ end