activesambaldap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.en +9 -0
- data/NEWS.ja +10 -0
- data/README.en +310 -0
- data/README.ja +307 -0
- data/Rakefile +95 -0
- data/bin/asl-groupadd +70 -0
- data/bin/asl-groupdel +58 -0
- data/bin/asl-groupmod +133 -0
- data/bin/asl-groupshow +31 -0
- data/bin/asl-passwd +99 -0
- data/bin/asl-populate +96 -0
- data/bin/asl-purge +24 -0
- data/bin/asl-samba-computeradd +94 -0
- data/bin/asl-samba-groupadd +55 -0
- data/bin/asl-samba-groupdel +53 -0
- data/bin/asl-samba-groupmod +98 -0
- data/bin/asl-samba-useradd +98 -0
- data/bin/asl-samba-userdel +47 -0
- data/bin/asl-samba-usermod +92 -0
- data/bin/asl-useradd +263 -0
- data/bin/asl-userdel +75 -0
- data/bin/asl-usermod +335 -0
- data/bin/asl-usershow +31 -0
- data/lib/active_samba_ldap/account.rb +199 -0
- data/lib/active_samba_ldap/base.rb +126 -0
- data/lib/active_samba_ldap/command.rb +94 -0
- data/lib/active_samba_ldap/computer.rb +13 -0
- data/lib/active_samba_ldap/computer_account.rb +34 -0
- data/lib/active_samba_ldap/configuration.rb +322 -0
- data/lib/active_samba_ldap/dc.rb +17 -0
- data/lib/active_samba_ldap/entry.rb +80 -0
- data/lib/active_samba_ldap/group.rb +182 -0
- data/lib/active_samba_ldap/idmap.rb +17 -0
- data/lib/active_samba_ldap/ou.rb +18 -0
- data/lib/active_samba_ldap/populate.rb +254 -0
- data/lib/active_samba_ldap/samba_account.rb +200 -0
- data/lib/active_samba_ldap/samba_computer.rb +20 -0
- data/lib/active_samba_ldap/samba_group.rb +126 -0
- data/lib/active_samba_ldap/samba_user.rb +39 -0
- data/lib/active_samba_ldap/unix_id_pool.rb +41 -0
- data/lib/active_samba_ldap/user.rb +14 -0
- data/lib/active_samba_ldap/user_account.rb +30 -0
- data/lib/active_samba_ldap/version.rb +3 -0
- data/lib/active_samba_ldap.rb +29 -0
- data/lib/samba/encrypt.rb +86 -0
- data/misc/rd2html.rb +42 -0
- data/rails/plugin/active_samba_ldap/README +30 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/scaffold_asl_generator.rb +28 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/computer.rb +3 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/dc.rb +3 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/group.rb +3 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/idmap.rb +3 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/ldap.yml +24 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/ou.rb +3 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_controller.rb +12 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_helper.rb +2 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_index.rhtml +17 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_populate.rhtml +15 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_purge.rhtml +10 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/unix_id_pool.rb +3 -0
- data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/user.rb +3 -0
- data/rails/plugin/active_samba_ldap/init.rb +6 -0
- data/test/asl-test-utils.rb +276 -0
- data/test/command.rb +64 -0
- data/test/config.yaml.sample +17 -0
- data/test/run-test.rb +18 -0
- data/test/test-unit-ext/always-show-result.rb +28 -0
- data/test/test-unit-ext/priority.rb +159 -0
- data/test/test-unit-ext.rb +2 -0
- data/test/test_asl_groupadd.rb +69 -0
- data/test/test_asl_groupdel.rb +88 -0
- data/test/test_asl_groupmod.rb +256 -0
- data/test/test_asl_groupshow.rb +21 -0
- data/test/test_asl_passwd.rb +125 -0
- data/test/test_asl_populate.rb +92 -0
- data/test/test_asl_purge.rb +21 -0
- data/test/test_asl_useradd.rb +710 -0
- data/test/test_asl_userdel.rb +73 -0
- data/test/test_asl_usermod.rb +541 -0
- data/test/test_asl_usershow.rb +27 -0
- data/test/test_group.rb +21 -0
- data/test/test_password.rb +51 -0
- data/test/test_samba_encrypt.rb +36 -0
- data/test/test_user_home_directory.rb +43 -0
- metadata +177 -0
data/Rakefile
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'find'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
base_dir = File.expand_path(File.dirname(__FILE__))
|
7
|
+
truncate_base_dir = Proc.new do |x|
|
8
|
+
x.gsub(/^#{Regexp.escape(base_dir + File::SEPARATOR)}/, '')
|
9
|
+
end
|
10
|
+
|
11
|
+
_binding = binding
|
12
|
+
eval(File.read("#{base_dir}/lib/active_samba_ldap.rb"), _binding)
|
13
|
+
eval('require_gem_if_need.call("hoe")', _binding)
|
14
|
+
|
15
|
+
manifest = File.join(base_dir, "Manifest.txt")
|
16
|
+
manifest_contents = []
|
17
|
+
base_dir_included_components = %w(README.ja README.en NEWS.ja NEWS.en setup.rb
|
18
|
+
Rakefile)
|
19
|
+
excluded_components = %w(.svn .test-result .config Manifest.txt config.yml doc
|
20
|
+
pkg setup.rb post-setup.rb html config.yaml)
|
21
|
+
excluded_suffixes = %w(.help)
|
22
|
+
Find.find(base_dir) do |target|
|
23
|
+
target = truncate_base_dir[target]
|
24
|
+
components = target.split(File::SEPARATOR)
|
25
|
+
if components.size == 1 and !File.directory?(target)
|
26
|
+
next unless base_dir_included_components.include?(components[0])
|
27
|
+
end
|
28
|
+
Find.prune if (excluded_components - components) != excluded_components
|
29
|
+
next if excluded_suffixes.include?(File.extname(target))
|
30
|
+
manifest_contents << target if File.file?(target)
|
31
|
+
end
|
32
|
+
|
33
|
+
File.open(manifest, "w") do |f|
|
34
|
+
f.puts manifest_contents.sort.join("\n")
|
35
|
+
end
|
36
|
+
at_exit do
|
37
|
+
FileUtils.rm_f(manifest)
|
38
|
+
end
|
39
|
+
|
40
|
+
def cleanup_white_space(entry)
|
41
|
+
entry.gsub(/(\A\n+|\n+\z)/, '') + "\n"
|
42
|
+
end
|
43
|
+
|
44
|
+
class Hoe
|
45
|
+
attr_accessor :full_name
|
46
|
+
|
47
|
+
alias_method :announcement_original, :announcement
|
48
|
+
def announcement
|
49
|
+
name_orig = name
|
50
|
+
self.name = full_name
|
51
|
+
announcement_original
|
52
|
+
ensure
|
53
|
+
self_name = name_orig
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
ENV["VERSION"] = ActiveSambaLdap::VERSION
|
58
|
+
project = Hoe.new("activesambaldap", ActiveSambaLdap::VERSION) do |p|
|
59
|
+
p.rubyforge_name = "asl"
|
60
|
+
p.name = p.rubyforge_name if ARGV.include?("public_docs")
|
61
|
+
p.full_name = "ActiveSambaLdap"
|
62
|
+
p.summary = "Samba+LDAP administration tools"
|
63
|
+
p.extra_deps << ["activeldap", ">= 0.8.0"]
|
64
|
+
p.email = "kou@cozmixng.org"
|
65
|
+
p.author = "Kouhei Sutou"
|
66
|
+
p.url = "http://asl.rubyforge.org/"
|
67
|
+
p.rdoc_pattern = /^(lib|bin)|txt$|\.(en|ja)$/
|
68
|
+
|
69
|
+
news_of_current_release = File.read("NEWS.en").split(/^==\s.*$/)[1]
|
70
|
+
p.changes = cleanup_white_space(news_of_current_release)
|
71
|
+
|
72
|
+
entries = File.read("README.en").split(/^==\s(.*)$/)
|
73
|
+
whats_this = cleanup_white_space(entries[entries.index("What\'s this?") + 1])
|
74
|
+
p.summary, p.description, = whats_this.split(/\n\n+/, 3)
|
75
|
+
end
|
76
|
+
|
77
|
+
rdoc_task = nil
|
78
|
+
if ObjectSpace.each_object(Rake::RDocTask) {|rdoc_task|} != 1
|
79
|
+
puts "hoe may be changed"
|
80
|
+
end
|
81
|
+
rdoc_task.main = "README.en"
|
82
|
+
rdoc_task.options << "--charset=UTF-8"
|
83
|
+
rdoc_task.template = "kilmer"
|
84
|
+
rdoc_task.rdoc_files -= project.bin_files
|
85
|
+
rdoc_task.rdoc_files += project.bin_files.collect {|x| "#{x}.help"}
|
86
|
+
|
87
|
+
project.bin_files.each do |bin|
|
88
|
+
bin_help = "#{bin}.help"
|
89
|
+
File.open(bin_help, "w") do |f|
|
90
|
+
f.puts(`#{RUBY} -I #{File.join(base_dir, 'lib')} #{bin} --help`)
|
91
|
+
end
|
92
|
+
at_exit do
|
93
|
+
FileUtils.rm_f(bin_help)
|
94
|
+
end
|
95
|
+
end
|
data/bin/asl-groupadd
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'active_samba_ldap'
|
4
|
+
require 'active_samba_ldap/command'
|
5
|
+
|
6
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
7
|
+
options.gid = nil
|
8
|
+
options.group_type = "domain"
|
9
|
+
options.print_gid_number = false
|
10
|
+
|
11
|
+
opts.banner += " GROUP_NAME"
|
12
|
+
|
13
|
+
opts.on("-g", "--gid=GID", Integer, "GID number") {|options.gid|}
|
14
|
+
opts.on("-t", "--type=TYPE",
|
15
|
+
"group type (#{options.group_type})") {|options.group_type|}
|
16
|
+
opts.on("-p", "--[no-]print-gid-number",
|
17
|
+
"print the gid number to stdout",
|
18
|
+
"(#{options.print_gid_number})") {|options.print_gid_number|}
|
19
|
+
end
|
20
|
+
|
21
|
+
name = nil
|
22
|
+
if argv.size == 1
|
23
|
+
name = argv.first
|
24
|
+
else
|
25
|
+
$stderr.puts opts
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
|
29
|
+
unless Process.uid.zero?
|
30
|
+
$stderr.puts "need root authority."
|
31
|
+
exit 1
|
32
|
+
end
|
33
|
+
|
34
|
+
ActiveSambaLdap::Base.establish_connection("update")
|
35
|
+
|
36
|
+
class Group < ActiveSambaLdap::SambaGroup
|
37
|
+
ldap_mapping
|
38
|
+
end
|
39
|
+
|
40
|
+
class UnixIdPool < ActiveSambaLdap::UnixIdPool
|
41
|
+
ldap_mapping
|
42
|
+
end
|
43
|
+
|
44
|
+
if Group.exists?(name)
|
45
|
+
$stderr.puts "group '#{name}' already exists."
|
46
|
+
exit 1
|
47
|
+
end
|
48
|
+
|
49
|
+
create_options = {
|
50
|
+
:cn => name,
|
51
|
+
:gid_number => options.gid,
|
52
|
+
:pool_class => UnixIdPool,
|
53
|
+
:group_type => options.group_type,
|
54
|
+
}
|
55
|
+
group = Group.create(create_options)
|
56
|
+
|
57
|
+
unless group.errors.empty?
|
58
|
+
group.errors.each_full do |message|
|
59
|
+
$stderr.puts(message)
|
60
|
+
end
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
|
64
|
+
if options.print_gid_number
|
65
|
+
puts group.gid_number
|
66
|
+
end
|
67
|
+
|
68
|
+
ActiveSambaLdap::Base.restart_nscd
|
69
|
+
|
70
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
data/bin/asl-groupdel
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'active_samba_ldap'
|
4
|
+
require 'active_samba_ldap/command'
|
5
|
+
|
6
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
7
|
+
options.force = false
|
8
|
+
|
9
|
+
opts.banner += " GROUP_NAME"
|
10
|
+
|
11
|
+
opts.on("-f", "--[no-]force",
|
12
|
+
"force delete group (#{options.force})") {|options.force|}
|
13
|
+
end
|
14
|
+
|
15
|
+
name = nil
|
16
|
+
if argv.size == 1
|
17
|
+
name = argv.first
|
18
|
+
else
|
19
|
+
$stderr.puts opts
|
20
|
+
exit 1
|
21
|
+
end
|
22
|
+
|
23
|
+
unless Process.uid.zero?
|
24
|
+
$stderr.puts "need root authority."
|
25
|
+
exit 1
|
26
|
+
end
|
27
|
+
|
28
|
+
ActiveSambaLdap::Base.establish_connection("update")
|
29
|
+
|
30
|
+
class Group < ActiveSambaLdap::SambaGroup
|
31
|
+
ldap_mapping
|
32
|
+
end
|
33
|
+
|
34
|
+
class User < ActiveSambaLdap::SambaUser
|
35
|
+
ldap_mapping
|
36
|
+
end
|
37
|
+
|
38
|
+
class Computer < ActiveSambaLdap::SambaComputer
|
39
|
+
ldap_mapping
|
40
|
+
end
|
41
|
+
|
42
|
+
unless Group.exists?(name)
|
43
|
+
$stderr.puts "group '#{name}' doesn't exist."
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
group = Group.find(name)
|
47
|
+
|
48
|
+
begin
|
49
|
+
group.destroy(:remove_members => true,
|
50
|
+
:force_change_primary_members => options.force)
|
51
|
+
rescue ActiveSambaLdap::Error
|
52
|
+
$stderr.puts $!
|
53
|
+
exit 1
|
54
|
+
end
|
55
|
+
|
56
|
+
ActiveSambaLdap::Base.restart_nscd
|
57
|
+
|
58
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
data/bin/asl-groupmod
ADDED
@@ -0,0 +1,133 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'active_samba_ldap'
|
4
|
+
require 'active_samba_ldap/command'
|
5
|
+
|
6
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
7
|
+
options.gid = nil
|
8
|
+
options.allow_non_unique_gid_number = false
|
9
|
+
options.new_group_name = nil
|
10
|
+
options.members_to_add = nil
|
11
|
+
options.members_to_delete = nil
|
12
|
+
|
13
|
+
opts.banner += " GROUP_NAME"
|
14
|
+
|
15
|
+
opts.on("-g", "--gid=GID", "gid") {|options.gid|}
|
16
|
+
opts.on("--[no-]allow-non-unique-gid",
|
17
|
+
"gid can be non unique " +
|
18
|
+
"(#{options.allow_non_unique_gid_number})") do |bool|
|
19
|
+
options.allow_non_unique_gid_number = bool
|
20
|
+
end
|
21
|
+
opts.on("-r", "--rename=NEW_NAME",
|
22
|
+
"new group name") {|options.new_group_name|}
|
23
|
+
opts.on("-a", "--add-members=MEMBER1,MEMBER2,MEBMER3", Array,
|
24
|
+
"add members (comma delimited)") {|options.members_to_add|}
|
25
|
+
opts.on("-d", "--delete-members=MEMBER1,MEMBER2,MEBMER3", Array,
|
26
|
+
"delete members (comma delimited)") {|options.members_to_delete|}
|
27
|
+
end
|
28
|
+
|
29
|
+
name = nil
|
30
|
+
if argv.size == 1
|
31
|
+
name = argv.first
|
32
|
+
else
|
33
|
+
$stderr.puts opts
|
34
|
+
exit 1
|
35
|
+
end
|
36
|
+
|
37
|
+
unless Process.uid.zero?
|
38
|
+
$stderr.puts "need root authority."
|
39
|
+
exit 1
|
40
|
+
end
|
41
|
+
|
42
|
+
ActiveSambaLdap::Base.establish_connection("update")
|
43
|
+
|
44
|
+
class Group < ActiveSambaLdap::SambaGroup
|
45
|
+
ldap_mapping
|
46
|
+
end
|
47
|
+
|
48
|
+
class User < ActiveSambaLdap::SambaUser
|
49
|
+
ldap_mapping
|
50
|
+
end
|
51
|
+
|
52
|
+
class Computer < ActiveSambaLdap::SambaComputer
|
53
|
+
ldap_mapping
|
54
|
+
end
|
55
|
+
|
56
|
+
unless Group.exists?(name)
|
57
|
+
$stderr.puts "group '#{name}' doesn't exist."
|
58
|
+
exit 1
|
59
|
+
end
|
60
|
+
group = Group.find(name)
|
61
|
+
|
62
|
+
if options.gid
|
63
|
+
begin
|
64
|
+
group.change_gid_number(options.gid, options.allow_non_unique_gid_number)
|
65
|
+
rescue ActiveSambaLdap::GidNumberAlreadyExists
|
66
|
+
$stderr.puts $!.message
|
67
|
+
exit 1
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
if options.members_to_add and options.members_to_delete
|
72
|
+
duplicated_members = options.members_to_add & options.members_to_delete
|
73
|
+
unless duplicated_members.empty?
|
74
|
+
message = "there are duplicated members in adding and deleting members: "
|
75
|
+
message << duplicated_members.join(", ")
|
76
|
+
$stderr.puts message
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
if options.members_to_add
|
82
|
+
users = []
|
83
|
+
computers = []
|
84
|
+
options.members_to_add.each do |member|
|
85
|
+
if /\$$/ =~ member
|
86
|
+
computers << Computer.find(member)
|
87
|
+
else
|
88
|
+
users << User.find(member)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
group.users.concat(users)
|
92
|
+
group.computers.concat(computers)
|
93
|
+
end
|
94
|
+
|
95
|
+
if options.members_to_delete
|
96
|
+
users = []
|
97
|
+
computers = []
|
98
|
+
options.members_to_delete.each do |member|
|
99
|
+
if /\$$/ =~ member
|
100
|
+
computers << Computer.find(member)
|
101
|
+
else
|
102
|
+
users << User.find(member)
|
103
|
+
end
|
104
|
+
end
|
105
|
+
group.users -= users
|
106
|
+
group.computers -= computers
|
107
|
+
end
|
108
|
+
|
109
|
+
group.save!
|
110
|
+
|
111
|
+
if options.new_group_name
|
112
|
+
if Group.exists?(options.new_group_name)
|
113
|
+
$stderr.puts "group '#{options.new_group_name}' always exists."
|
114
|
+
exit 1
|
115
|
+
end
|
116
|
+
|
117
|
+
new_group = Group.new(options.new_group_name)
|
118
|
+
new_group.attributes = group.attributes.reject do |key, value|
|
119
|
+
%w(cn).include?(key)
|
120
|
+
end
|
121
|
+
primary_members = group.primary_members
|
122
|
+
group.gid_number = nil
|
123
|
+
new_group.save!
|
124
|
+
primary_members.each do |member|
|
125
|
+
member.primary_group = new_group
|
126
|
+
member.save!
|
127
|
+
end
|
128
|
+
group.destroy(:remove_members => true)
|
129
|
+
end
|
130
|
+
|
131
|
+
ActiveSambaLdap::Base.restart_nscd
|
132
|
+
|
133
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
data/bin/asl-groupshow
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'active_samba_ldap'
|
4
|
+
require 'active_samba_ldap/command'
|
5
|
+
|
6
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
7
|
+
opts.banner += " GROUP_NAME"
|
8
|
+
end
|
9
|
+
|
10
|
+
name = nil
|
11
|
+
if argv.size == 1
|
12
|
+
name = argv.first
|
13
|
+
else
|
14
|
+
$stderr.puts opts
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
|
18
|
+
ActiveSambaLdap::Base.establish_connection("reference")
|
19
|
+
|
20
|
+
class Group < ActiveSambaLdap::SambaGroup
|
21
|
+
ldap_mapping
|
22
|
+
end
|
23
|
+
|
24
|
+
unless Group.exists?(name)
|
25
|
+
$stderr.puts "group '#{name}' doesn't exist."
|
26
|
+
exit 1
|
27
|
+
end
|
28
|
+
group = Group.find(name)
|
29
|
+
puts group.to_ldif
|
30
|
+
|
31
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
data/bin/asl-passwd
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'etc'
|
4
|
+
|
5
|
+
require 'active_samba_ldap'
|
6
|
+
require 'active_samba_ldap/command'
|
7
|
+
|
8
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
9
|
+
options.update_samba_password = true
|
10
|
+
options.update_unix_password = true
|
11
|
+
|
12
|
+
opts.banner += " [USER_NAME]"
|
13
|
+
|
14
|
+
opts.on("-s", "--[no-]samba-password",
|
15
|
+
"update samba password (#{options.update_samba_password})") do |bool|
|
16
|
+
options.update_samba_password = bool
|
17
|
+
end
|
18
|
+
|
19
|
+
opts.on("-u", "--[no-]unix-password",
|
20
|
+
"update UNIX password (#{options.update_unix_password})") do |bool|
|
21
|
+
options.update_unix_password = bool
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
name = nil
|
26
|
+
case argv.size
|
27
|
+
when 0
|
28
|
+
name = Etc.getpwuid(Process.uid).name
|
29
|
+
when 1
|
30
|
+
name = argv.first
|
31
|
+
else
|
32
|
+
$stderr.puts opts
|
33
|
+
exit 1
|
34
|
+
end
|
35
|
+
|
36
|
+
if !options.update_samba_password and !options.update_unix_password
|
37
|
+
$stderr.puts "do nothing"
|
38
|
+
exit
|
39
|
+
end
|
40
|
+
|
41
|
+
ActiveSambaLdap::Base.establish_connection("update")
|
42
|
+
|
43
|
+
if options.update_samba_password
|
44
|
+
parent = ActiveSambaLdap::SambaUser
|
45
|
+
else
|
46
|
+
parent = ActiveSambaLdap::User
|
47
|
+
end
|
48
|
+
|
49
|
+
class User < parent
|
50
|
+
ldap_mapping
|
51
|
+
end
|
52
|
+
|
53
|
+
unless User.exists?(name)
|
54
|
+
$stderr.puts "user '#{name}' doesn't exist."
|
55
|
+
exit 1
|
56
|
+
end
|
57
|
+
user = User.find(name)
|
58
|
+
|
59
|
+
unless Process.uid.zero?
|
60
|
+
prompt = "Enter your current password: "
|
61
|
+
old_password = ActiveSambaLdap::Command.read_password(prompt)
|
62
|
+
|
63
|
+
auth_class = Class.new(ActiveSambaLdap::Base)
|
64
|
+
config = ActiveSambaLdap::Base.configurations["reference"].symbolize_keys
|
65
|
+
begin
|
66
|
+
auth_class.establish_connection(config.merge(:bind_dn => user.dn,
|
67
|
+
:password => old_password,
|
68
|
+
:allow_anonymous => false))
|
69
|
+
rescue ActiveLdap::AuthenticationError
|
70
|
+
$stderr.puts "password isn't match"
|
71
|
+
exit 1
|
72
|
+
ensure
|
73
|
+
auth_class.remove_connection
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
password = ActiveSambaLdap::Command.read_password("New password: ")
|
78
|
+
password2 = ActiveSambaLdap::Command.read_password("Retype new password: ")
|
79
|
+
|
80
|
+
unless password == password2
|
81
|
+
$stderr.puts "New passwords don't match."
|
82
|
+
exit 1
|
83
|
+
end
|
84
|
+
|
85
|
+
changed = false
|
86
|
+
|
87
|
+
if options.update_unix_password
|
88
|
+
user.change_password(password)
|
89
|
+
changed = true
|
90
|
+
end
|
91
|
+
|
92
|
+
if options.update_samba_password
|
93
|
+
user.change_samba_password(password)
|
94
|
+
changed = true
|
95
|
+
end
|
96
|
+
|
97
|
+
user.save! if changed
|
98
|
+
|
99
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
data/bin/asl-populate
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'etc'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
require 'active_samba_ldap'
|
8
|
+
require 'active_samba_ldap/command'
|
9
|
+
|
10
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
11
|
+
default = ActiveSambaLdap::Configuration::ClassMethods::Private.new({})
|
12
|
+
options.start_uid = Integer(default.start_uid)
|
13
|
+
options.start_gid = Integer(default.start_gid)
|
14
|
+
options.administrator = ActiveSambaLdap::SambaUser::DOMAIN_ADMIN_NAME
|
15
|
+
admin_rid = ActiveSambaLdap::SambaUser::DOMAIN_ADMIN_RID
|
16
|
+
admins_rid = ActiveSambaLdap::SambaGroup::DOMAIN_ADMINS_RID
|
17
|
+
guest_rid = ActiveSambaLdap::SambaUser::DOMAIN_GUEST_RID
|
18
|
+
guests_rid = ActiveSambaLdap::SambaGroup::DOMAIN_GUESTS_RID
|
19
|
+
options.administrator_uid = ActiveSambaLdap::SambaUser.rid2uid(admin_rid)
|
20
|
+
options.administrator_gid = ActiveSambaLdap::SambaGroup.rid2gid(admins_rid)
|
21
|
+
options.guest = ActiveSambaLdap::SambaUser::DOMAIN_GUEST_NAME
|
22
|
+
options.guest_uid = ActiveSambaLdap::SambaUser.rid2uid(guest_rid)
|
23
|
+
options.guest_gid = ActiveSambaLdap::SambaGroup.rid2gid(guests_rid)
|
24
|
+
options.export_ldif = nil
|
25
|
+
options.import_ldif = nil
|
26
|
+
|
27
|
+
opts.on("-u", "--start-uid=UID", Integer,
|
28
|
+
"first uid number to allocate",
|
29
|
+
"(#{options.start_uid})") {|options.start_uid|}
|
30
|
+
opts.on("-g", "--start-gid=GID", Integer,
|
31
|
+
"first gid number to allocate",
|
32
|
+
"(#{options.start_gid})") {|options.start_gid|}
|
33
|
+
opts.on("-a", "--administrator=NAME",
|
34
|
+
"administrator login name",
|
35
|
+
"(#{options.administrator})") {|options.administrator|}
|
36
|
+
opts.on("--administrator-uid=UID", Integer,
|
37
|
+
"administrator's uid number",
|
38
|
+
"(#{options.administrator_uid})") {|options.administrator_uid|}
|
39
|
+
opts.on("--administrator-gid=GID", Integer,
|
40
|
+
"administrator's gid number",
|
41
|
+
"(#{options.administrator_gid})") {|options.administrator_gid|}
|
42
|
+
opts.on("-g", "--guest=NAME",
|
43
|
+
"guest login name (#{options.guest})") {|options.guest|}
|
44
|
+
opts.on("--guest-uid=UID", Integer,
|
45
|
+
"guest's uid number (#{options.guest_uid})") {|options.guest_uid|}
|
46
|
+
opts.on("--guest-gid=GID", Integer,
|
47
|
+
"guest's gid number (#{options.guest_gid})") {|options.guest_gid|}
|
48
|
+
opts.on("-e", "--export-ldif=LDIF",
|
49
|
+
"export LDIF file") {|options.export_ldif|}
|
50
|
+
# opts.on("-i", "--import-ldif=LDIF",
|
51
|
+
# "import LDIF file") {|options.import_ldif|}
|
52
|
+
end
|
53
|
+
|
54
|
+
unless Process.uid.zero?
|
55
|
+
$stderr.puts "need root authority."
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
|
59
|
+
ActiveSambaLdap::Base.establish_connection("update")
|
60
|
+
|
61
|
+
entries, opts = ActiveSambaLdap::Base.populate(options.marshal_dump)
|
62
|
+
|
63
|
+
def init_administrator(opts, entries)
|
64
|
+
admin_name = opts[:administrator]
|
65
|
+
user_class = opts[:user_class]
|
66
|
+
admin = entries.find do |entry|
|
67
|
+
entry.is_a?(user_class) and entry.uid == admin_name
|
68
|
+
end
|
69
|
+
return if admin.new_entry?
|
70
|
+
|
71
|
+
prompt = "Password for #{admin_name}: "
|
72
|
+
password = ActiveSambaLdap::Command.read_password(prompt)
|
73
|
+
prompt2 = "Retype password for #{admin_name}: "
|
74
|
+
password2 = ActiveSambaLdap::Command.read_password(prompt2)
|
75
|
+
unless password == password2
|
76
|
+
$stderr.puts "Passwords don't match."
|
77
|
+
exit 1
|
78
|
+
end
|
79
|
+
|
80
|
+
admin.change_password(password)
|
81
|
+
admin.change_samba_password(password)
|
82
|
+
admin.enable
|
83
|
+
admin.save!
|
84
|
+
end
|
85
|
+
|
86
|
+
init_administrator(opts, entries)
|
87
|
+
|
88
|
+
if options.export_ldif
|
89
|
+
File.open(options.export_ldif, "w") do |out|
|
90
|
+
out.puts(entries.join("\n"))
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
ActiveSambaLdap::Base.restart_nscd
|
95
|
+
|
96
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
data/bin/asl-purge
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'fileutils'
|
4
|
+
require 'etc'
|
5
|
+
require 'time'
|
6
|
+
|
7
|
+
require 'active_samba_ldap'
|
8
|
+
require 'active_samba_ldap/command'
|
9
|
+
|
10
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
11
|
+
end
|
12
|
+
|
13
|
+
unless Process.uid.zero?
|
14
|
+
$stderr.puts "need root authority."
|
15
|
+
exit 1
|
16
|
+
end
|
17
|
+
|
18
|
+
ActiveSambaLdap::Base.establish_connection("update")
|
19
|
+
|
20
|
+
ActiveSambaLdap::Base.purge
|
21
|
+
|
22
|
+
ActiveSambaLdap::Base.restart_nscd
|
23
|
+
|
24
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
@@ -0,0 +1,94 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'active_samba_ldap'
|
4
|
+
require 'active_samba_ldap/command'
|
5
|
+
|
6
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
7
|
+
options.ou = nil
|
8
|
+
|
9
|
+
opts.banner += " COMPUTER_NAME"
|
10
|
+
|
11
|
+
opts.on("-o", "--ou=OU",
|
12
|
+
"add the user in the organizational unit OU",
|
13
|
+
"(relative to the user suffix)") do |ou|
|
14
|
+
if /^ou=/ =~ ou
|
15
|
+
options.ou = ou
|
16
|
+
else
|
17
|
+
options.ou = "ou=#{ou}"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
name = nil
|
23
|
+
if argv.size == 1
|
24
|
+
name = argv.first.chomp("$") + "$"
|
25
|
+
else
|
26
|
+
$stderr.puts opts
|
27
|
+
exit 1
|
28
|
+
end
|
29
|
+
|
30
|
+
unless Process.uid.zero?
|
31
|
+
$stderr.puts "need root authority."
|
32
|
+
exit 1
|
33
|
+
end
|
34
|
+
|
35
|
+
ActiveSambaLdap::Base.establish_connection("update")
|
36
|
+
|
37
|
+
|
38
|
+
class User < ActiveSambaLdap::User
|
39
|
+
ldap_mapping
|
40
|
+
end
|
41
|
+
|
42
|
+
class Computer < ActiveSambaLdap::Computer
|
43
|
+
ldap_mapping
|
44
|
+
end
|
45
|
+
|
46
|
+
class Group < ActiveSambaLdap::Group
|
47
|
+
ldap_mapping
|
48
|
+
end
|
49
|
+
|
50
|
+
class UnixIdPool < ActiveSambaLdap::UnixIdPool
|
51
|
+
ldap_mapping
|
52
|
+
end
|
53
|
+
|
54
|
+
unless Computer.valid_name?(name)
|
55
|
+
$stderr.puts "'#{name}' is illegal computer name"
|
56
|
+
exit 1
|
57
|
+
end
|
58
|
+
|
59
|
+
if Computer.exists?(name)
|
60
|
+
$stderr.puts "computer '#{name}' already exists."
|
61
|
+
exit 1
|
62
|
+
end
|
63
|
+
|
64
|
+
create_options = {
|
65
|
+
:uid => [name, options.ou].compact.join(","),
|
66
|
+
:group_class => Group,
|
67
|
+
}
|
68
|
+
|
69
|
+
create_options[:description] = "Computer"
|
70
|
+
create_options[:gecos] = "Computer"
|
71
|
+
|
72
|
+
computer = nil
|
73
|
+
begin
|
74
|
+
computer = Computer.create(:uid => name, :group_class => Group)
|
75
|
+
rescue ActiveSambaLdap::UidNumberAlreadyExists
|
76
|
+
$stderr.puts "UID '#{uid_number}' already exists"
|
77
|
+
exit 1
|
78
|
+
rescue ActiveSambaLdap::GidNumberDoesNotExist,
|
79
|
+
ActiveSambaLdap::GroupDoesNotExist,
|
80
|
+
ActiveSambaLdap::GroupDoesNotHaveSambaSID
|
81
|
+
$stderr.puts $!
|
82
|
+
exit 1
|
83
|
+
end
|
84
|
+
|
85
|
+
unless computer.errors.empty?
|
86
|
+
computer.errors.each_full do |message|
|
87
|
+
$stderr.puts(message)
|
88
|
+
end
|
89
|
+
exit 1
|
90
|
+
end
|
91
|
+
|
92
|
+
ActiveSambaLdap::Base.restart_nscd
|
93
|
+
|
94
|
+
ActiveSambaLdap::Base.clear_active_connections!
|