powerhome-activeldap 3.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.yardopts +6 -0
- data/COPYING +340 -0
- data/Gemfile +12 -0
- data/LICENSE +59 -0
- data/README.textile +140 -0
- data/TODO +32 -0
- data/benchmark/README.md +64 -0
- data/benchmark/bench-backend.rb +247 -0
- data/benchmark/bench-instantiate.rb +98 -0
- data/benchmark/config.yaml.sample +5 -0
- data/doc/text/development.textile +54 -0
- data/doc/text/news.textile +811 -0
- data/doc/text/rails.textile +144 -0
- data/doc/text/tutorial.textile +1010 -0
- data/examples/config.yaml.example +5 -0
- data/examples/example.der +0 -0
- data/examples/example.jpg +0 -0
- data/examples/groupadd +41 -0
- data/examples/groupdel +35 -0
- data/examples/groupls +49 -0
- data/examples/groupmod +42 -0
- data/examples/lpasswd +55 -0
- data/examples/objects/group.rb +13 -0
- data/examples/objects/ou.rb +4 -0
- data/examples/objects/user.rb +20 -0
- data/examples/ouadd +38 -0
- data/examples/useradd +45 -0
- data/examples/useradd-binary +53 -0
- data/examples/userdel +34 -0
- data/examples/userls +50 -0
- data/examples/usermod +42 -0
- data/examples/usermod-binary-add +50 -0
- data/examples/usermod-binary-add-time +54 -0
- data/examples/usermod-binary-del +48 -0
- data/examples/usermod-lang-add +43 -0
- data/lib/active_ldap.rb +85 -0
- data/lib/active_ldap/action_controller/ldap_benchmarking.rb +55 -0
- data/lib/active_ldap/acts/tree.rb +78 -0
- data/lib/active_ldap/adapter/base.rb +707 -0
- data/lib/active_ldap/adapter/jndi.rb +184 -0
- data/lib/active_ldap/adapter/jndi_connection.rb +185 -0
- data/lib/active_ldap/adapter/ldap.rb +290 -0
- data/lib/active_ldap/adapter/ldap_ext.rb +105 -0
- data/lib/active_ldap/adapter/net_ldap.rb +309 -0
- data/lib/active_ldap/adapter/net_ldap_ext.rb +23 -0
- data/lib/active_ldap/association/belongs_to.rb +47 -0
- data/lib/active_ldap/association/belongs_to_many.rb +58 -0
- data/lib/active_ldap/association/children.rb +21 -0
- data/lib/active_ldap/association/collection.rb +105 -0
- data/lib/active_ldap/association/has_many.rb +31 -0
- data/lib/active_ldap/association/has_many_utils.rb +44 -0
- data/lib/active_ldap/association/has_many_wrap.rb +75 -0
- data/lib/active_ldap/association/proxy.rb +107 -0
- data/lib/active_ldap/associations.rb +205 -0
- data/lib/active_ldap/attribute_methods.rb +23 -0
- data/lib/active_ldap/attribute_methods/before_type_cast.rb +24 -0
- data/lib/active_ldap/attribute_methods/dirty.rb +43 -0
- data/lib/active_ldap/attribute_methods/query.rb +31 -0
- data/lib/active_ldap/attribute_methods/read.rb +44 -0
- data/lib/active_ldap/attribute_methods/write.rb +38 -0
- data/lib/active_ldap/attributes.rb +176 -0
- data/lib/active_ldap/base.rb +1410 -0
- data/lib/active_ldap/callbacks.rb +71 -0
- data/lib/active_ldap/command.rb +49 -0
- data/lib/active_ldap/compatible.rb +44 -0
- data/lib/active_ldap/configuration.rb +147 -0
- data/lib/active_ldap/connection.rb +299 -0
- data/lib/active_ldap/distinguished_name.rb +291 -0
- data/lib/active_ldap/entry_attribute.rb +78 -0
- data/lib/active_ldap/escape.rb +12 -0
- data/lib/active_ldap/get_text.rb +20 -0
- data/lib/active_ldap/get_text/parser.rb +161 -0
- data/lib/active_ldap/helper.rb +92 -0
- data/lib/active_ldap/human_readable.rb +133 -0
- data/lib/active_ldap/ldap_error.rb +74 -0
- data/lib/active_ldap/ldif.rb +930 -0
- data/lib/active_ldap/log_subscriber.rb +50 -0
- data/lib/active_ldap/object_class.rb +95 -0
- data/lib/active_ldap/operations.rb +624 -0
- data/lib/active_ldap/persistence.rb +100 -0
- data/lib/active_ldap/populate.rb +53 -0
- data/lib/active_ldap/railtie.rb +43 -0
- data/lib/active_ldap/railties/controller_runtime.rb +48 -0
- data/lib/active_ldap/schema.rb +701 -0
- data/lib/active_ldap/schema/syntaxes.rb +422 -0
- data/lib/active_ldap/timeout.rb +75 -0
- data/lib/active_ldap/timeout_stub.rb +17 -0
- data/lib/active_ldap/user_password.rb +99 -0
- data/lib/active_ldap/validations.rb +200 -0
- data/lib/active_ldap/version.rb +3 -0
- data/lib/active_ldap/xml.rb +139 -0
- data/lib/rails/generators/active_ldap/model/USAGE +18 -0
- data/lib/rails/generators/active_ldap/model/model_generator.rb +47 -0
- data/lib/rails/generators/active_ldap/model/templates/model_active_ldap.rb +3 -0
- data/lib/rails/generators/active_ldap/scaffold/scaffold_generator.rb +14 -0
- data/lib/rails/generators/active_ldap/scaffold/templates/ldap.yml +19 -0
- data/po/en/active-ldap.po +4029 -0
- data/po/ja/active-ldap.po +4060 -0
- data/test/add-phonetic-attribute-options-to-slapd.ldif +10 -0
- data/test/al-test-utils.rb +428 -0
- data/test/command.rb +111 -0
- data/test/config.yaml.sample +6 -0
- data/test/fixtures/lower_case_object_class_schema.rb +802 -0
- data/test/run-test.rb +34 -0
- data/test/test_acts_as_tree.rb +60 -0
- data/test/test_adapter.rb +121 -0
- data/test/test_associations.rb +701 -0
- data/test/test_attributes.rb +117 -0
- data/test/test_base.rb +1214 -0
- data/test/test_base_per_instance.rb +61 -0
- data/test/test_bind.rb +62 -0
- data/test/test_callback.rb +31 -0
- data/test/test_configuration.rb +40 -0
- data/test/test_connection.rb +82 -0
- data/test/test_connection_per_class.rb +112 -0
- data/test/test_connection_per_dn.rb +112 -0
- data/test/test_dirty.rb +98 -0
- data/test/test_dn.rb +172 -0
- data/test/test_find.rb +176 -0
- data/test/test_groupadd.rb +50 -0
- data/test/test_groupdel.rb +46 -0
- data/test/test_groupls.rb +107 -0
- data/test/test_groupmod.rb +51 -0
- data/test/test_ldif.rb +1890 -0
- data/test/test_load.rb +133 -0
- data/test/test_lpasswd.rb +75 -0
- data/test/test_object_class.rb +74 -0
- data/test/test_persistence.rb +131 -0
- data/test/test_reflection.rb +175 -0
- data/test/test_schema.rb +559 -0
- data/test/test_syntax.rb +444 -0
- data/test/test_user.rb +217 -0
- data/test/test_user_password.rb +108 -0
- data/test/test_useradd-binary.rb +62 -0
- data/test/test_useradd.rb +57 -0
- data/test/test_userdel.rb +48 -0
- data/test/test_userls.rb +91 -0
- data/test/test_usermod-binary-add-time.rb +65 -0
- data/test/test_usermod-binary-add.rb +64 -0
- data/test/test_usermod-binary-del.rb +66 -0
- data/test/test_usermod-lang-add.rb +59 -0
- data/test/test_usermod.rb +58 -0
- data/test/test_validation.rb +274 -0
- metadata +379 -0
Binary file
|
Binary file
|
data/examples/groupadd
ADDED
@@ -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
|
data/examples/groupdel
ADDED
@@ -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)
|
data/examples/groupls
ADDED
@@ -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(', ')}")
|
data/examples/groupmod
ADDED
@@ -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
|
data/examples/lpasswd
ADDED
@@ -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,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
|
data/examples/ouadd
ADDED
@@ -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
|
data/examples/useradd
ADDED
@@ -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
|
+
|
data/examples/userdel
ADDED
@@ -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)
|