adtools 0.0.1pre
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.
- data/.gitignore +4 -0
- data/Gemfile +3 -0
- data/License +2 -0
- data/Rakefile +3 -0
- data/Readme.rdoc +26 -0
- data/adtools.gemspec +21 -0
- data/lib/adtools.rb +112 -0
- data/lib/adtools/base.rb +584 -0
- data/lib/adtools/computer.rb +35 -0
- data/lib/adtools/config.rb +43 -0
- data/lib/adtools/container.rb +114 -0
- data/lib/adtools/field_type/binary.rb +39 -0
- data/lib/adtools/field_type/date.rb +39 -0
- data/lib/adtools/field_type/dn_array.rb +40 -0
- data/lib/adtools/field_type/group_dn_array.rb +40 -0
- data/lib/adtools/field_type/member_dn_array.rb +47 -0
- data/lib/adtools/field_type/password.rb +41 -0
- data/lib/adtools/field_type/timestamp.rb +45 -0
- data/lib/adtools/field_type/user_dn_array.rb +40 -0
- data/lib/adtools/group.rb +137 -0
- data/lib/adtools/member.rb +53 -0
- data/lib/adtools/ou.rb +11 -0
- data/lib/adtools/user.rb +152 -0
- data/lib/adtools/version.rb +3 -0
- data/spec/adtools_computer_spec.rb +15 -0
- data/spec/adtools_ou_spec.rb +15 -0
- data/spec/adtools_spec.rb +43 -0
- data/spec/spec_helper.rb +18 -0
- metadata +128 -0
|
@@ -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 Adtools
|
|
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,43 @@
|
|
|
1
|
+
module Adtools
|
|
2
|
+
class Config
|
|
3
|
+
attr_accessor :domain, :port, :base, :server, :query_user, :query_password
|
|
4
|
+
|
|
5
|
+
# Creates a new instance of ActiveDirectory::Config
|
|
6
|
+
#
|
|
7
|
+
# Sets port, allowed_groups, denied_groups, ad_sv_attrs and ad_mv_attrs to default so they can be omitted from the config
|
|
8
|
+
def initialize
|
|
9
|
+
@port = 389
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Sets domain valiable
|
|
13
|
+
#
|
|
14
|
+
# Called as:
|
|
15
|
+
# ActiveDirectory::Config.domain=(s)
|
|
16
|
+
#
|
|
17
|
+
# Calculates both base string and server
|
|
18
|
+
def domain=(s)
|
|
19
|
+
@domain = s
|
|
20
|
+
work_out_base(s)
|
|
21
|
+
@server ||= s
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def settings_hash
|
|
25
|
+
{
|
|
26
|
+
:host => @server,
|
|
27
|
+
:base => @base,
|
|
28
|
+
:port => @port,
|
|
29
|
+
:auth => {
|
|
30
|
+
:method => :simple,
|
|
31
|
+
:username => "#{@query_user}@#{@domain}",
|
|
32
|
+
:password => @query_password
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def work_out_base(s)
|
|
40
|
+
@base ||= s.gsub(/\./,', dc=').gsub(/^/,"dc=")
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
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 Adtools
|
|
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 Adtools
|
|
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 Adtools
|
|
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 Adtools
|
|
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 Adtools
|
|
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 Adtools
|
|
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 Adtools
|
|
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
|