powerhome-activeldap 3.2.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (145) hide show
  1. checksums.yaml +7 -0
  2. data/.yardopts +6 -0
  3. data/COPYING +340 -0
  4. data/Gemfile +12 -0
  5. data/LICENSE +59 -0
  6. data/README.textile +140 -0
  7. data/TODO +32 -0
  8. data/benchmark/README.md +64 -0
  9. data/benchmark/bench-backend.rb +247 -0
  10. data/benchmark/bench-instantiate.rb +98 -0
  11. data/benchmark/config.yaml.sample +5 -0
  12. data/doc/text/development.textile +54 -0
  13. data/doc/text/news.textile +811 -0
  14. data/doc/text/rails.textile +144 -0
  15. data/doc/text/tutorial.textile +1010 -0
  16. data/examples/config.yaml.example +5 -0
  17. data/examples/example.der +0 -0
  18. data/examples/example.jpg +0 -0
  19. data/examples/groupadd +41 -0
  20. data/examples/groupdel +35 -0
  21. data/examples/groupls +49 -0
  22. data/examples/groupmod +42 -0
  23. data/examples/lpasswd +55 -0
  24. data/examples/objects/group.rb +13 -0
  25. data/examples/objects/ou.rb +4 -0
  26. data/examples/objects/user.rb +20 -0
  27. data/examples/ouadd +38 -0
  28. data/examples/useradd +45 -0
  29. data/examples/useradd-binary +53 -0
  30. data/examples/userdel +34 -0
  31. data/examples/userls +50 -0
  32. data/examples/usermod +42 -0
  33. data/examples/usermod-binary-add +50 -0
  34. data/examples/usermod-binary-add-time +54 -0
  35. data/examples/usermod-binary-del +48 -0
  36. data/examples/usermod-lang-add +43 -0
  37. data/lib/active_ldap.rb +85 -0
  38. data/lib/active_ldap/action_controller/ldap_benchmarking.rb +55 -0
  39. data/lib/active_ldap/acts/tree.rb +78 -0
  40. data/lib/active_ldap/adapter/base.rb +707 -0
  41. data/lib/active_ldap/adapter/jndi.rb +184 -0
  42. data/lib/active_ldap/adapter/jndi_connection.rb +185 -0
  43. data/lib/active_ldap/adapter/ldap.rb +290 -0
  44. data/lib/active_ldap/adapter/ldap_ext.rb +105 -0
  45. data/lib/active_ldap/adapter/net_ldap.rb +309 -0
  46. data/lib/active_ldap/adapter/net_ldap_ext.rb +23 -0
  47. data/lib/active_ldap/association/belongs_to.rb +47 -0
  48. data/lib/active_ldap/association/belongs_to_many.rb +58 -0
  49. data/lib/active_ldap/association/children.rb +21 -0
  50. data/lib/active_ldap/association/collection.rb +105 -0
  51. data/lib/active_ldap/association/has_many.rb +31 -0
  52. data/lib/active_ldap/association/has_many_utils.rb +44 -0
  53. data/lib/active_ldap/association/has_many_wrap.rb +75 -0
  54. data/lib/active_ldap/association/proxy.rb +107 -0
  55. data/lib/active_ldap/associations.rb +205 -0
  56. data/lib/active_ldap/attribute_methods.rb +23 -0
  57. data/lib/active_ldap/attribute_methods/before_type_cast.rb +24 -0
  58. data/lib/active_ldap/attribute_methods/dirty.rb +43 -0
  59. data/lib/active_ldap/attribute_methods/query.rb +31 -0
  60. data/lib/active_ldap/attribute_methods/read.rb +44 -0
  61. data/lib/active_ldap/attribute_methods/write.rb +38 -0
  62. data/lib/active_ldap/attributes.rb +176 -0
  63. data/lib/active_ldap/base.rb +1410 -0
  64. data/lib/active_ldap/callbacks.rb +71 -0
  65. data/lib/active_ldap/command.rb +49 -0
  66. data/lib/active_ldap/compatible.rb +44 -0
  67. data/lib/active_ldap/configuration.rb +147 -0
  68. data/lib/active_ldap/connection.rb +299 -0
  69. data/lib/active_ldap/distinguished_name.rb +291 -0
  70. data/lib/active_ldap/entry_attribute.rb +78 -0
  71. data/lib/active_ldap/escape.rb +12 -0
  72. data/lib/active_ldap/get_text.rb +20 -0
  73. data/lib/active_ldap/get_text/parser.rb +161 -0
  74. data/lib/active_ldap/helper.rb +92 -0
  75. data/lib/active_ldap/human_readable.rb +133 -0
  76. data/lib/active_ldap/ldap_error.rb +74 -0
  77. data/lib/active_ldap/ldif.rb +930 -0
  78. data/lib/active_ldap/log_subscriber.rb +50 -0
  79. data/lib/active_ldap/object_class.rb +95 -0
  80. data/lib/active_ldap/operations.rb +624 -0
  81. data/lib/active_ldap/persistence.rb +100 -0
  82. data/lib/active_ldap/populate.rb +53 -0
  83. data/lib/active_ldap/railtie.rb +43 -0
  84. data/lib/active_ldap/railties/controller_runtime.rb +48 -0
  85. data/lib/active_ldap/schema.rb +701 -0
  86. data/lib/active_ldap/schema/syntaxes.rb +422 -0
  87. data/lib/active_ldap/timeout.rb +75 -0
  88. data/lib/active_ldap/timeout_stub.rb +17 -0
  89. data/lib/active_ldap/user_password.rb +99 -0
  90. data/lib/active_ldap/validations.rb +200 -0
  91. data/lib/active_ldap/version.rb +3 -0
  92. data/lib/active_ldap/xml.rb +139 -0
  93. data/lib/rails/generators/active_ldap/model/USAGE +18 -0
  94. data/lib/rails/generators/active_ldap/model/model_generator.rb +47 -0
  95. data/lib/rails/generators/active_ldap/model/templates/model_active_ldap.rb +3 -0
  96. data/lib/rails/generators/active_ldap/scaffold/scaffold_generator.rb +14 -0
  97. data/lib/rails/generators/active_ldap/scaffold/templates/ldap.yml +19 -0
  98. data/po/en/active-ldap.po +4029 -0
  99. data/po/ja/active-ldap.po +4060 -0
  100. data/test/add-phonetic-attribute-options-to-slapd.ldif +10 -0
  101. data/test/al-test-utils.rb +428 -0
  102. data/test/command.rb +111 -0
  103. data/test/config.yaml.sample +6 -0
  104. data/test/fixtures/lower_case_object_class_schema.rb +802 -0
  105. data/test/run-test.rb +34 -0
  106. data/test/test_acts_as_tree.rb +60 -0
  107. data/test/test_adapter.rb +121 -0
  108. data/test/test_associations.rb +701 -0
  109. data/test/test_attributes.rb +117 -0
  110. data/test/test_base.rb +1214 -0
  111. data/test/test_base_per_instance.rb +61 -0
  112. data/test/test_bind.rb +62 -0
  113. data/test/test_callback.rb +31 -0
  114. data/test/test_configuration.rb +40 -0
  115. data/test/test_connection.rb +82 -0
  116. data/test/test_connection_per_class.rb +112 -0
  117. data/test/test_connection_per_dn.rb +112 -0
  118. data/test/test_dirty.rb +98 -0
  119. data/test/test_dn.rb +172 -0
  120. data/test/test_find.rb +176 -0
  121. data/test/test_groupadd.rb +50 -0
  122. data/test/test_groupdel.rb +46 -0
  123. data/test/test_groupls.rb +107 -0
  124. data/test/test_groupmod.rb +51 -0
  125. data/test/test_ldif.rb +1890 -0
  126. data/test/test_load.rb +133 -0
  127. data/test/test_lpasswd.rb +75 -0
  128. data/test/test_object_class.rb +74 -0
  129. data/test/test_persistence.rb +131 -0
  130. data/test/test_reflection.rb +175 -0
  131. data/test/test_schema.rb +559 -0
  132. data/test/test_syntax.rb +444 -0
  133. data/test/test_user.rb +217 -0
  134. data/test/test_user_password.rb +108 -0
  135. data/test/test_useradd-binary.rb +62 -0
  136. data/test/test_useradd.rb +57 -0
  137. data/test/test_userdel.rb +48 -0
  138. data/test/test_userls.rb +91 -0
  139. data/test/test_usermod-binary-add-time.rb +65 -0
  140. data/test/test_usermod-binary-add.rb +64 -0
  141. data/test/test_usermod-binary-del.rb +66 -0
  142. data/test/test_usermod-lang-add.rb +59 -0
  143. data/test/test_usermod.rb +58 -0
  144. data/test/test_validation.rb +274 -0
  145. metadata +379 -0
@@ -0,0 +1,5 @@
1
+ host: 127.0.0.1
2
+ method: :tls
3
+ base: dc=localdomain
4
+ bind_dn: cn=admin,dc=localdomain
5
+ #adapter: net-ldap
Binary file
Binary file
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ if Group.exists?(name)
30
+ $stderr.puts("Group #{name} already exists.")
31
+ exit 1
32
+ end
33
+
34
+ group = Group.new(name)
35
+ group.gid_number = 9000
36
+
37
+ unless group.save
38
+ puts "failed"
39
+ puts group.errors.full_messages
40
+ exit 1
41
+ end
@@ -0,0 +1,35 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+
30
+ unless Group.exists?(name)
31
+ $stderr.puts("Group #{name} doesn't exist.")
32
+ exit 1
33
+ end
34
+
35
+ Group.destroy(name)
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ unless Group.exists?(name)
30
+ $stderr.puts("Group #{name} doesn't exist.")
31
+ exit 1
32
+ end
33
+
34
+ group = Group.find(name)
35
+
36
+ members = []
37
+ group.primary_members.each do |mem|
38
+ members << "#{mem.uid}[#{mem.uidNumber}]"
39
+ end
40
+
41
+ group.members.each do |mem|
42
+ if mem.new_entry?
43
+ members << "#{mem.uid}[????]"
44
+ else
45
+ members << "#{mem.uid}[#{mem.uidNumber}]"
46
+ end
47
+ end
48
+
49
+ puts("#{group.id}(#{group.gid_number}): #{members.join(', ')}")
@@ -0,0 +1,42 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " GROUP_NAME GID_NUMBER"
13
+ end
14
+
15
+ if argv.size == 2
16
+ name, gid = argv
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+
30
+ unless Group.exists?(name)
31
+ $stderr.puts("Group #{name} doesn't exist.")
32
+ exit 1
33
+ end
34
+
35
+ group = Group.find(name)
36
+ group.gid_number = gid
37
+
38
+ unless group.save
39
+ puts "failed"
40
+ puts group.errors.full_messages
41
+ exit 1
42
+ end
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " USER_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ user ||= ENV["USER"]
24
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
25
+ end
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ unless User.exists?(name)
30
+ $stderr.puts("User #{name} doesn't exist.")
31
+ exit 1
32
+ end
33
+
34
+ class PasswordMismatch < RuntimeError
35
+ end
36
+
37
+ user = User.find(name)
38
+ count = 0
39
+ begin
40
+ count += 1
41
+ pw1 = pwb.call(user.dn)
42
+ pw2 = pwb.call(user.dn)
43
+ raise PasswordMismatch if pw1 != pw2
44
+ rescue PasswordMismatch
45
+ puts "Password mismatch!"
46
+ exit 1 if count == 3
47
+ retry
48
+ end
49
+
50
+ user.user_password = ActiveLdap::UserPassword.ssha(pw1)
51
+ unless user.save
52
+ puts "failed"
53
+ puts user.errors.full_messages
54
+ exit 1
55
+ end
@@ -0,0 +1,13 @@
1
+ class Group < ActiveLdap::Base
2
+ ldap_mapping :dn_attribute => "cn",
3
+ :classes => ['posixGroup']
4
+ # Inspired by ActiveRecord, this tells ActiveLDAP that the
5
+ # LDAP entry has a attribute which contains one or more of
6
+ # some class |:class_name| where the attributes name is
7
+ # |:local_key|. This means that it will call
8
+ # :class_name.new(value_of(:local_key)) to create the objects.
9
+ has_many :members, :class_name => "User", :wrap => "memberUid"
10
+ has_many :primary_members, :class_name => 'User',
11
+ :foreign_key => 'gidNumber',
12
+ :primary_key => 'gidNumber'
13
+ end # Group
@@ -0,0 +1,4 @@
1
+ class Ou < ActiveLdap::Base
2
+ ldap_mapping :dn_attribute => 'ou', :prefix => '',
3
+ :classes => ['top', 'organizationalUnit']
4
+ end
@@ -0,0 +1,20 @@
1
+ require 'objects/group'
2
+
3
+ class User < ActiveLdap::Base
4
+ ldap_mapping :dn_attribute => 'uid', :prefix => 'ou=People',
5
+ :classes => ['person', 'posixAccount']
6
+ belongs_to :primary_group, :class_name => "Group",
7
+ :foreign_key => "gidNumber", :primary_key => "gidNumber"
8
+ belongs_to :groups, :many => 'memberUid'
9
+
10
+ # An example of using the old "return_objects" API with the
11
+ # new ActiveRecord-style API.
12
+ alias groups_mapping groups
13
+ def groups(return_objects=true)
14
+ return groups_mapping if return_objects
15
+ attr = 'cn'
16
+ Group.search(:attribute => 'memberUid',
17
+ :value => id,
18
+ :attributes => [attr]).map {|dn, attrs| attrs[attr]}.flatten
19
+ end
20
+ end
@@ -0,0 +1,38 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/ou'
9
+
10
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
11
+ opts.banner += " name"
12
+ end
13
+
14
+ if argv.size == 1
15
+ name = argv[0]
16
+ else
17
+ $stderr.puts opts
18
+ exit 1
19
+ end
20
+
21
+ pwb = Proc.new do |user|
22
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
23
+ end
24
+
25
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
26
+ :allow_anonymous => false)
27
+
28
+ if Ou.exists?(name)
29
+ $stderr.puts("Ou #{name} already exists.")
30
+ exit 1
31
+ end
32
+
33
+ ou = Ou.new(name)
34
+ unless ou.save
35
+ puts "failed"
36
+ puts ou.errors.full_messages
37
+ exit 1
38
+ end
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " USER_NAME CN UID"
13
+ end
14
+
15
+ if argv.size == 3
16
+ name, cn, uid = argv
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ if User.exists?(name)
30
+ $stderr.puts("User #{name} already exists.")
31
+ exit 1
32
+ end
33
+
34
+ user = User.new(name)
35
+ user.add_class('shadowAccount')
36
+ user.cn = cn
37
+ user.uid_number = uid
38
+ user.gid_number = uid
39
+ user.home_directory = "/home/#{name}"
40
+ user.sn = "somesn"
41
+ unless user.save
42
+ puts "failed"
43
+ puts user.errors.full_messages
44
+ exit 1
45
+ end
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " USER_NAME CN UID"
13
+ end
14
+
15
+ if argv.size == 3
16
+ name, cn, uid = argv
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ if User.exists?(name)
30
+ $stderr.puts("User #{name} already exists.")
31
+ exit 1
32
+ end
33
+
34
+ user = User.new(name)
35
+ user.add_class('shadowAccount')
36
+ user.cn = cn
37
+ user.sn = "somesn"
38
+ user.uid_number = uid
39
+ user.gid_number = uid
40
+ user.home_directory = "/home/#{name}"
41
+ user.add_class('strongAuthenticationUser')
42
+ cert_file = File.join(File.dirname(__FILE__), 'example.der')
43
+ File.open(cert_file) do |input|
44
+ input.set_encoding("ascii-8bit") if input.respond_to?(:set_encoding)
45
+ user.user_certificate = input.read
46
+ end
47
+
48
+ unless user.save
49
+ puts "failed"
50
+ puts user.errors.full_messages
51
+ exit 1
52
+ end
53
+
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby
2
+
3
+ base = File.expand_path(File.join(File.dirname(__FILE__), ".."))
4
+ $LOAD_PATH << File.join(base, "lib")
5
+ $LOAD_PATH << File.join(base, "examples")
6
+
7
+ require 'active_ldap'
8
+ require 'objects/user'
9
+ require 'objects/group'
10
+
11
+ argv, opts, options = ActiveLdap::Command.parse_options do |opts, options|
12
+ opts.banner += " USER_NAME"
13
+ end
14
+
15
+ if argv.size == 1
16
+ name = argv.shift
17
+ else
18
+ $stderr.puts opts
19
+ exit 1
20
+ end
21
+
22
+ pwb = Proc.new do |user|
23
+ ActiveLdap::Command.read_password("[#{user}] Password: ")
24
+ end
25
+
26
+ ActiveLdap::Base.setup_connection(:password_block => pwb,
27
+ :allow_anonymous => false)
28
+
29
+ unless User.exists?(name)
30
+ $stderr.puts("User #{name} doesn't exist.")
31
+ exit 1
32
+ end
33
+
34
+ User.destroy(name)