ActiveSambaLdap 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- data/NEWS.en +40 -0
- data/NEWS.ja +44 -0
- data/README.en +366 -0
- data/README.ja +361 -0
- data/Rakefile +168 -0
- data/bin/asl-groupadd +73 -0
- data/bin/asl-groupadd.help +1 -0
- data/bin/asl-groupdel +61 -0
- data/bin/asl-groupdel.help +1 -0
- data/bin/asl-groupmod +137 -0
- data/bin/asl-groupmod.help +1 -0
- data/bin/asl-groupshow +33 -0
- data/bin/asl-groupshow.help +1 -0
- data/bin/asl-passwd +90 -0
- data/bin/asl-passwd.help +1 -0
- data/bin/asl-populate +101 -0
- data/bin/asl-populate.help +1 -0
- data/bin/asl-purge +26 -0
- data/bin/asl-purge.help +1 -0
- data/bin/asl-samba-computeradd +96 -0
- data/bin/asl-samba-computeradd.help +1 -0
- data/bin/asl-samba-groupadd +57 -0
- data/bin/asl-samba-groupadd.help +1 -0
- data/bin/asl-samba-groupdel +55 -0
- data/bin/asl-samba-groupdel.help +1 -0
- data/bin/asl-samba-groupmod +99 -0
- data/bin/asl-samba-groupmod.help +1 -0
- data/bin/asl-samba-useradd +100 -0
- data/bin/asl-samba-useradd.help +1 -0
- data/bin/asl-samba-userdel +49 -0
- data/bin/asl-samba-userdel.help +1 -0
- data/bin/asl-samba-usermod +94 -0
- data/bin/asl-samba-usermod.help +1 -0
- data/bin/asl-useradd +264 -0
- data/bin/asl-useradd.help +1 -0
- data/bin/asl-userdel +84 -0
- data/bin/asl-userdel.help +1 -0
- data/bin/asl-usermod +335 -0
- data/bin/asl-usermod.help +1 -0
- data/bin/asl-usershow +33 -0
- data/bin/asl-usershow.help +1 -0
- data/lib/active_samba_ldap.rb +42 -0
- data/lib/active_samba_ldap/account_entry.rb +208 -0
- data/lib/active_samba_ldap/base.rb +137 -0
- data/lib/active_samba_ldap/command.rb +100 -0
- data/lib/active_samba_ldap/computer.rb +24 -0
- data/lib/active_samba_ldap/computer_account_entry.rb +34 -0
- data/lib/active_samba_ldap/configuration.rb +333 -0
- data/lib/active_samba_ldap/dc.rb +19 -0
- data/lib/active_samba_ldap/entry.rb +81 -0
- data/lib/active_samba_ldap/get_text_support.rb +12 -0
- data/lib/active_samba_ldap/group.rb +17 -0
- data/lib/active_samba_ldap/group_entry.rb +187 -0
- data/lib/active_samba_ldap/idmap.rb +19 -0
- data/lib/active_samba_ldap/ou.rb +20 -0
- data/lib/active_samba_ldap/populate.rb +257 -0
- data/lib/active_samba_ldap/reloadable.rb +15 -0
- data/lib/active_samba_ldap/samba_account_entry.rb +225 -0
- data/lib/active_samba_ldap/samba_entry.rb +26 -0
- data/lib/active_samba_ldap/samba_group_entry.rb +143 -0
- data/lib/active_samba_ldap/unix_id_pool.rb +43 -0
- data/lib/active_samba_ldap/user.rb +44 -0
- data/lib/active_samba_ldap/user_account_entry.rb +30 -0
- data/lib/active_samba_ldap/version.rb +3 -0
- data/lib/samba/encrypt.rb +86 -0
- data/misc/rd2html.rb +42 -0
- data/po/ja/active-samba-ldap.po +465 -0
- data/rails/README +30 -0
- data/rails/init.rb +33 -0
- data/rails_generators/scaffold_active_samba_ldap/scaffold_active_samba_ldap_generator.rb +27 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/computer.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/dc.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/group.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/idmap.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/ldap.yml +24 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/ou.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_controller.rb +12 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_helper.rb +2 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_index.rhtml +17 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_populate.rhtml +15 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/samba_purge.rhtml +10 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/unix_id_pool.rb +3 -0
- data/rails_generators/scaffold_active_samba_ldap/templates/user.rb +3 -0
- data/setup.rb +1585 -0
- data/test-unit/History.txt +107 -0
- data/test-unit/README.txt +52 -0
- data/test-unit/Rakefile +40 -0
- data/test-unit/TODO +5 -0
- data/test-unit/bin/testrb +5 -0
- data/test-unit/lib/test/unit.rb +342 -0
- data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
- data/test-unit/lib/test/unit/assertions.rb +1149 -0
- data/test-unit/lib/test/unit/attribute.rb +125 -0
- data/test-unit/lib/test/unit/autorunner.rb +329 -0
- data/test-unit/lib/test/unit/collector.rb +43 -0
- data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
- data/test-unit/lib/test/unit/collector/dir.rb +108 -0
- data/test-unit/lib/test/unit/collector/load.rb +135 -0
- data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
- data/test-unit/lib/test/unit/color-scheme.rb +86 -0
- data/test-unit/lib/test/unit/color.rb +96 -0
- data/test-unit/lib/test/unit/diff.rb +538 -0
- data/test-unit/lib/test/unit/error.rb +124 -0
- data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
- data/test-unit/lib/test/unit/failure.rb +110 -0
- data/test-unit/lib/test/unit/fixture.rb +176 -0
- data/test-unit/lib/test/unit/notification.rb +125 -0
- data/test-unit/lib/test/unit/omission.rb +143 -0
- data/test-unit/lib/test/unit/pending.rb +146 -0
- data/test-unit/lib/test/unit/priority.rb +181 -0
- data/test-unit/lib/test/unit/runner/console.rb +52 -0
- data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
- data/test-unit/lib/test/unit/testcase.rb +425 -0
- data/test-unit/lib/test/unit/testresult.rb +89 -0
- data/test-unit/lib/test/unit/testsuite.rb +110 -0
- data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
- data/test-unit/lib/test/unit/ui/console/testrunner.rb +223 -0
- data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
- data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
- data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
- data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
- data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
- data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
- data/test-unit/lib/test/unit/util/observable.rb +90 -0
- data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
- data/test-unit/lib/test/unit/version.rb +7 -0
- data/test-unit/sample/adder.rb +13 -0
- data/test-unit/sample/subtracter.rb +12 -0
- data/test-unit/sample/tc_adder.rb +18 -0
- data/test-unit/sample/tc_subtracter.rb +18 -0
- data/test-unit/sample/test_user.rb +22 -0
- data/test-unit/sample/ts_examples.rb +7 -0
- data/test-unit/test/collector/test-descendant.rb +135 -0
- data/test-unit/test/collector/test-load.rb +333 -0
- data/test-unit/test/collector/test_dir.rb +406 -0
- data/test-unit/test/collector/test_objectspace.rb +98 -0
- data/test-unit/test/run-test.rb +13 -0
- data/test-unit/test/test-attribute.rb +86 -0
- data/test-unit/test/test-color-scheme.rb +56 -0
- data/test-unit/test/test-color.rb +47 -0
- data/test-unit/test/test-diff.rb +477 -0
- data/test-unit/test/test-emacs-runner.rb +60 -0
- data/test-unit/test/test-fixture.rb +287 -0
- data/test-unit/test/test-notification.rb +33 -0
- data/test-unit/test/test-omission.rb +81 -0
- data/test-unit/test/test-pending.rb +70 -0
- data/test-unit/test/test-priority.rb +119 -0
- data/test-unit/test/test-testcase.rb +507 -0
- data/test-unit/test/test_assertions.rb +1082 -0
- data/test-unit/test/test_error.rb +26 -0
- data/test-unit/test/test_failure.rb +33 -0
- data/test-unit/test/test_testresult.rb +113 -0
- data/test-unit/test/test_testsuite.rb +129 -0
- data/test-unit/test/testunit-test-util.rb +14 -0
- data/test-unit/test/ui/test_testrunmediator.rb +20 -0
- data/test-unit/test/util/test-method-owner-finder.rb +38 -0
- data/test-unit/test/util/test_backtracefilter.rb +41 -0
- data/test-unit/test/util/test_observable.rb +102 -0
- data/test-unit/test/util/test_procwrapper.rb +36 -0
- data/test/asl-test-utils.rb +276 -0
- data/test/command.rb +67 -0
- data/test/config.yaml.sample +17 -0
- data/test/run-test.rb +20 -0
- data/test/test_asl_groupadd.rb +69 -0
- data/test/test_asl_groupdel.rb +88 -0
- data/test/test_asl_groupmod.rb +259 -0
- data/test/test_asl_groupshow.rb +21 -0
- data/test/test_asl_passwd.rb +126 -0
- data/test/test_asl_populate.rb +92 -0
- data/test/test_asl_purge.rb +21 -0
- data/test/test_asl_useradd.rb +712 -0
- data/test/test_asl_userdel.rb +75 -0
- data/test/test_asl_usermod.rb +549 -0
- data/test/test_asl_usershow.rb +27 -0
- data/test/test_entry.rb +21 -0
- data/test/test_group.rb +21 -0
- data/test/test_password.rb +51 -0
- data/test/test_samba_encrypt.rb +35 -0
- data/test/test_user_home_directory.rb +43 -0
- metadata +314 -0
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'active_samba_ldap/reloadable'
|
2
|
+
|
3
|
+
module ActiveSambaLdap
|
4
|
+
class Error < StandardError
|
5
|
+
include ActiveSambaLdap::GetTextSupport
|
6
|
+
end
|
7
|
+
|
8
|
+
class MissingRequiredVariableError < Error
|
9
|
+
attr_reader :names
|
10
|
+
def initialize(names)
|
11
|
+
names = names.to_a
|
12
|
+
@names = names
|
13
|
+
super(n_("required variable is not set: %s",
|
14
|
+
"required variables are not set: %s",
|
15
|
+
names.size) % names.join(', '))
|
16
|
+
end
|
17
|
+
|
18
|
+
def name
|
19
|
+
@names.first
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
class UidNumberAlreadyExists < Error
|
24
|
+
attr_reader :number
|
25
|
+
def initialize(number)
|
26
|
+
@number = number
|
27
|
+
super(_("uid number already exists: %s") % number)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
class GroupDoesNotExist < Error
|
32
|
+
attr_reader :name
|
33
|
+
def initialize(name)
|
34
|
+
@name = name
|
35
|
+
super(_("group doesn't exist: %s") % name)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class GidNumberAlreadyExists < Error
|
40
|
+
attr_reader :number
|
41
|
+
def initialize(number)
|
42
|
+
@number = number
|
43
|
+
super(_("gid number already exists: %s") % number)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
class GidNumberDoesNotExist < Error
|
48
|
+
attr_reader :number
|
49
|
+
def initialize(number)
|
50
|
+
@number = number
|
51
|
+
super(_("gid number doesn't exist: %s") % number)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class GroupDoesNotHaveSambaSID < Error
|
56
|
+
attr_reader :number
|
57
|
+
def initialize(number)
|
58
|
+
@number = number
|
59
|
+
super(_("sambaSID attribute doesn't exist for gid number '%s'") % number)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
class CanNotChangePrimaryGroup < Error
|
64
|
+
attr_reader :group, :members
|
65
|
+
def initialize(group, members)
|
66
|
+
@group = group
|
67
|
+
@members = members
|
68
|
+
format = _("cannot change primary group from '%s' to other group " \
|
69
|
+
"due to no other belonged groups: %s")
|
70
|
+
super(format % [group, members.join(', ')])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class PrimaryGroupCanNotBeDestroyed < Error
|
75
|
+
attr_reader :group, :members
|
76
|
+
def initialize(group, members)
|
77
|
+
@group = group
|
78
|
+
@members = members
|
79
|
+
format = _("cannot destroy group '%s' due to members who belong " \
|
80
|
+
"to the group as primary group: %s")
|
81
|
+
super(format % [group, members.join(', ')])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
class InvalidConfigurationFormatError < Error
|
86
|
+
attr_reader :file, :location, :detail
|
87
|
+
def initialize(file, location, detail)
|
88
|
+
@file = file
|
89
|
+
@location = location
|
90
|
+
@detail = detail
|
91
|
+
format = _("found invalid configuration format at %s:%s: %s")
|
92
|
+
super(format % [file, location, detail])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
class InvalidConfigurationValueError < Error
|
97
|
+
attr_reader :name, :value, :detail
|
98
|
+
def initialize(name, value, detail)
|
99
|
+
@name = name
|
100
|
+
@value = value
|
101
|
+
@detail = detail
|
102
|
+
format = _("the value of %s '%s' is invalid: %s")
|
103
|
+
super(format % [name, value.inspect, detail])
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
class NotSambaAavialableError < Error
|
108
|
+
attr_reader :object
|
109
|
+
def initialize(object)
|
110
|
+
@object = object
|
111
|
+
super(_("%s is not Samba available") % [object.inspect])
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
115
|
+
class Base < ActiveLdap::Base
|
116
|
+
include Reloadable
|
117
|
+
|
118
|
+
class << self
|
119
|
+
def restart_nscd
|
120
|
+
nscd_working = system("/etc/init.d/nscd status >/dev/null 2>&1")
|
121
|
+
system("/etc/init.d/nscd stop >/dev/null 2>&1") if nscd_working
|
122
|
+
yield if block_given?
|
123
|
+
ensure
|
124
|
+
system("/etc/init.d/nscd start >/dev/null 2>&1") if nscd_working
|
125
|
+
end
|
126
|
+
|
127
|
+
private
|
128
|
+
def extract_ldap_mapping_options(options)
|
129
|
+
extracted_options = {}
|
130
|
+
ActiveLdap::Base::VALID_LDAP_MAPPING_OPTIONS.each do |key|
|
131
|
+
extracted_options[key] = options[key] if options.has_key?(key)
|
132
|
+
end
|
133
|
+
extracted_options
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
@@ -0,0 +1,100 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
require 'active_samba_ldap'
|
5
|
+
|
6
|
+
module ActiveSambaLdap
|
7
|
+
module Command
|
8
|
+
include ActiveSambaLdap::GetTextSupport
|
9
|
+
|
10
|
+
module_function
|
11
|
+
def parse_options(argv=nil)
|
12
|
+
argv ||= ARGV.dup
|
13
|
+
options = OpenStruct.new
|
14
|
+
configuration_files = default_configuration_files
|
15
|
+
opts = OptionParser.new do |opts|
|
16
|
+
yield(opts, options)
|
17
|
+
|
18
|
+
opts.separator("")
|
19
|
+
opts.separator(_("Common options:"))
|
20
|
+
|
21
|
+
opts.on_tail("--config=CONFIG",
|
22
|
+
_("Specify configuration file"),
|
23
|
+
_("Default configuration files:"),
|
24
|
+
*configuration_files.collect {|x| " #{x}"}) do |file|
|
25
|
+
configuration_files << file
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on_tail("-h", "--help", _("Show this message")) do
|
29
|
+
puts opts
|
30
|
+
exit
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on_tail("--version", _("Show version")) do
|
34
|
+
puts VERSION
|
35
|
+
exit
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
begin
|
40
|
+
opts.parse!(argv)
|
41
|
+
rescue OptionParser::ParseError
|
42
|
+
$stderr.puts($!)
|
43
|
+
$stderr.puts(opts)
|
44
|
+
exit 1
|
45
|
+
end
|
46
|
+
|
47
|
+
read_configuration_files(configuration_files)
|
48
|
+
|
49
|
+
[argv, opts, options]
|
50
|
+
end
|
51
|
+
|
52
|
+
def read_password(prompt, input=$stdin, output=$stdout)
|
53
|
+
output.print prompt
|
54
|
+
system "/bin/stty -echo" if input.tty?
|
55
|
+
password = input.gets
|
56
|
+
password = password.chomp if password
|
57
|
+
password
|
58
|
+
ensure
|
59
|
+
system "/bin/stty echo" if input.tty?
|
60
|
+
output.puts
|
61
|
+
end
|
62
|
+
|
63
|
+
def default_configuration_files
|
64
|
+
configuration_files = File.join(File.dirname(__FILE__),
|
65
|
+
"configuration_files")
|
66
|
+
if File.exists?(configuration_files)
|
67
|
+
files = File.readlines(configuration_files).collect do |line|
|
68
|
+
line.strip
|
69
|
+
end.reject do |line|
|
70
|
+
line.empty? or /^#/ =~ line
|
71
|
+
end
|
72
|
+
else
|
73
|
+
files = [
|
74
|
+
"/etc/activesambaldap/config.yaml",
|
75
|
+
"/etc/activesambaldap/bind.yaml",
|
76
|
+
]
|
77
|
+
end
|
78
|
+
begin
|
79
|
+
configuration_files_for_user = [
|
80
|
+
File.expand_path(File.join("~", ".activesambaldap.conf")),
|
81
|
+
File.expand_path(File.join("~", ".activesambaldap.bind")),
|
82
|
+
]
|
83
|
+
files.concat(configuration_files_for_user)
|
84
|
+
rescue ArgumentError
|
85
|
+
end
|
86
|
+
files
|
87
|
+
end
|
88
|
+
|
89
|
+
def read_configuration_files(files)
|
90
|
+
return if files.empty?
|
91
|
+
Base.configurations = files.inject({}) do |result, file|
|
92
|
+
if File.readable?(file)
|
93
|
+
result.merge(Configuration.read(file))
|
94
|
+
else
|
95
|
+
result
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'active_samba_ldap/base'
|
2
|
+
require 'active_samba_ldap/entry'
|
3
|
+
require 'active_samba_ldap/samba_entry'
|
4
|
+
require 'active_samba_ldap/account_entry'
|
5
|
+
require 'active_samba_ldap/computer_account_entry'
|
6
|
+
require 'active_samba_ldap/samba_account_entry'
|
7
|
+
|
8
|
+
module ActiveSambaLdap
|
9
|
+
class Computer < Base
|
10
|
+
include Reloadable
|
11
|
+
|
12
|
+
include Entry
|
13
|
+
include SambaEntry
|
14
|
+
|
15
|
+
include AccountEntry
|
16
|
+
include ComputerAccountEntry
|
17
|
+
include SambaAccountEntry
|
18
|
+
|
19
|
+
private
|
20
|
+
def default_account_flags
|
21
|
+
"[W]"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ActiveSambaLdap
|
2
|
+
module ComputerAccountEntry
|
3
|
+
NAME_RE = /\A#{AccountEntry::NAME_RE_SRC}\$\z/
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
super
|
7
|
+
base.extend(ClassMethods)
|
8
|
+
base.validates_format_of :uid, :with => NAME_RE
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def valid_name?(name)
|
13
|
+
NAME_RE =~ name ? true : false
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def default_prefix
|
18
|
+
configuration[:computers_suffix]
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def remove_from_group(group)
|
23
|
+
group.computers.delete(self)
|
24
|
+
end
|
25
|
+
|
26
|
+
def default_gid_number
|
27
|
+
self.class.configuration[:default_computer_gid]
|
28
|
+
end
|
29
|
+
|
30
|
+
def created_group_name
|
31
|
+
super.sub(/\$$/, '')
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,333 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
3
|
+
module ActiveSambaLdap
|
4
|
+
module Configuration
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
end
|
8
|
+
|
9
|
+
class << self
|
10
|
+
def read(file)
|
11
|
+
require 'yaml'
|
12
|
+
require 'erb'
|
13
|
+
erb = ERB.new(File.read(file))
|
14
|
+
erb.filename = file
|
15
|
+
result = nil
|
16
|
+
begin
|
17
|
+
begin
|
18
|
+
result = YAML.load(erb.result)
|
19
|
+
unless result
|
20
|
+
raise InvalidConfigurationFormatError.new(file, "0",
|
21
|
+
"empty source")
|
22
|
+
end
|
23
|
+
rescue ArgumentError
|
24
|
+
if /syntax error on line (\d+), col (\d+): `(.*)'/ =~ $!.message
|
25
|
+
raise InvalidConfigurationFormatError.new(file, "#{$1}:#{$2}", $3)
|
26
|
+
else
|
27
|
+
raise
|
28
|
+
end
|
29
|
+
end
|
30
|
+
rescue InvalidConfigurationFormatError
|
31
|
+
raise
|
32
|
+
rescue Exception
|
33
|
+
file, location = $@.first.split(/:/, 2)
|
34
|
+
detail = "#{$!.class}: #{$!.message}"
|
35
|
+
raise InvalidConfigurationFormatError.new(file, location, detail)
|
36
|
+
end
|
37
|
+
result
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
module ClassMethods
|
42
|
+
class ValidHash < Hash
|
43
|
+
def [](name)
|
44
|
+
if Private.required_variables.include?(name) and !has_key?(name)
|
45
|
+
raise MissingRequiredVariableError.new(name)
|
46
|
+
end
|
47
|
+
super(name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
def remove_connection_related_configuration(config)
|
52
|
+
target_keys = Private::VARIABLES.collect do |name|
|
53
|
+
name.to_sym
|
54
|
+
end - ActiveLdap::Adapter::Base::VALID_ADAPTER_CONFIGURATION_KEYS
|
55
|
+
super(config).reject do |key, value|
|
56
|
+
target_keys.include?(key)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def merge_configuration(config, *rest)
|
61
|
+
config = config.symbolize_keys
|
62
|
+
config = (configurations["common"] || {}).symbolize_keys.merge(config)
|
63
|
+
ValidHash.new.merge(super(Private.new(config).merge, *rest))
|
64
|
+
end
|
65
|
+
|
66
|
+
def required_configuration_variables(*names)
|
67
|
+
config = configuration
|
68
|
+
if config.nil?
|
69
|
+
missing_variables = names
|
70
|
+
else
|
71
|
+
missing_variables = names.find_all do |name|
|
72
|
+
config[name.to_sym].nil?
|
73
|
+
end
|
74
|
+
end
|
75
|
+
unless missing_variables.empty?
|
76
|
+
raise MissingRequiredVariableError.new(missing_variables)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
class Private
|
81
|
+
include ActiveSambaLdap::GetTextSupport
|
82
|
+
|
83
|
+
VARIABLES = %w(base host port scope bind_dn
|
84
|
+
password method allow_anonymous
|
85
|
+
|
86
|
+
sid smb_conf samba_domain samba_netbios_name
|
87
|
+
password_hash_type
|
88
|
+
|
89
|
+
users_suffix groups_suffix computers_suffix
|
90
|
+
idmap_suffix
|
91
|
+
|
92
|
+
start_uid start_gid
|
93
|
+
|
94
|
+
user_login_shell user_home_directory
|
95
|
+
user_home_directory_mode
|
96
|
+
user_gecos user_home_unc user_profile
|
97
|
+
user_home_drive user_logon_script mail_domain
|
98
|
+
|
99
|
+
skeleton_directory
|
100
|
+
|
101
|
+
default_user_gid default_computer_gid
|
102
|
+
default_max_password_age)
|
103
|
+
|
104
|
+
class << self
|
105
|
+
def required_variables
|
106
|
+
@required_variables ||= compute_required_variables
|
107
|
+
end
|
108
|
+
|
109
|
+
def compute_required_variables
|
110
|
+
not_required_variables = %w(base scope ldap_scope)
|
111
|
+
(VARIABLES - public_methods - not_required_variables).collect do |x|
|
112
|
+
x.to_sym
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
def initialize(target)
|
118
|
+
@target = target.symbolize_keys
|
119
|
+
end
|
120
|
+
|
121
|
+
def merge
|
122
|
+
result = @target.dup
|
123
|
+
VARIABLES.each do |variable|
|
124
|
+
key = variable.to_sym
|
125
|
+
result[key] ||= send(variable) if respond_to?(variable)
|
126
|
+
|
127
|
+
normalize_method = "normalize_#{variable}"
|
128
|
+
if respond_to?(normalize_method)
|
129
|
+
result[key] = __send__(normalize_method, result[key])
|
130
|
+
end
|
131
|
+
|
132
|
+
validate_method = "validate_#{variable}"
|
133
|
+
if respond_to?(validate_method)
|
134
|
+
__send__(validate_method, result[key])
|
135
|
+
end
|
136
|
+
end
|
137
|
+
result
|
138
|
+
end
|
139
|
+
|
140
|
+
def [](name)
|
141
|
+
@target[name.to_sym] || (respond_to?(name) ? send(name) : nil)
|
142
|
+
end
|
143
|
+
|
144
|
+
def sid
|
145
|
+
result = `net getlocalsid`
|
146
|
+
if $?.success?
|
147
|
+
result.chomp.gsub(/\G[^:]+:\s*/, '')
|
148
|
+
else
|
149
|
+
nil
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def smb_conf
|
154
|
+
%w(/etc/samba/smb.conf /usr/local/etc/samba/smb.conf).each do |guess|
|
155
|
+
return guess if File.exist?(guess)
|
156
|
+
end
|
157
|
+
nil
|
158
|
+
end
|
159
|
+
|
160
|
+
def samba_domain
|
161
|
+
_smb_conf = self["smb_conf"]
|
162
|
+
if _smb_conf
|
163
|
+
File.open(_smb_conf) do |f|
|
164
|
+
f.read.grep(/^\s*[^#;]/).each do |line|
|
165
|
+
if /^\s*workgroup\s*=\s*(\S+)\s*$/i =~ line
|
166
|
+
return $1.upcase
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
else
|
171
|
+
nil
|
172
|
+
end
|
173
|
+
end
|
174
|
+
|
175
|
+
def samba_netbios_name
|
176
|
+
netbios_name = nil
|
177
|
+
_smb_conf = self["smb_conf"]
|
178
|
+
if _smb_conf
|
179
|
+
File.open(_smb_conf) do |f|
|
180
|
+
f.read.grep(/^\s*[^#;]/).each do |line|
|
181
|
+
if /^\s*netbios\s*name\s*=\s*(.+)\s*$/i =~ line
|
182
|
+
netbios_name = $1
|
183
|
+
break
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
netbios_name ||= Socket.gethostname
|
189
|
+
netbios_name ? netbios_name.upcase : nil
|
190
|
+
end
|
191
|
+
|
192
|
+
def host
|
193
|
+
"localhost"
|
194
|
+
end
|
195
|
+
|
196
|
+
def port
|
197
|
+
389
|
198
|
+
end
|
199
|
+
|
200
|
+
def allow_anonymous
|
201
|
+
false
|
202
|
+
end
|
203
|
+
|
204
|
+
def method
|
205
|
+
:plain
|
206
|
+
end
|
207
|
+
|
208
|
+
def users_suffix
|
209
|
+
retrieve_value_from_smb_conf(/ldap\s+user\s+suffix/i) || "ou=Users"
|
210
|
+
end
|
211
|
+
|
212
|
+
def groups_suffix
|
213
|
+
retrieve_value_from_smb_conf(/ldap\s+group\s+suffix/i) || "ou=Groups"
|
214
|
+
end
|
215
|
+
|
216
|
+
def computers_suffix
|
217
|
+
retrieve_value_from_smb_conf(/ldap\s+machine\s+suffix/i) ||
|
218
|
+
"ou=Computers"
|
219
|
+
end
|
220
|
+
|
221
|
+
def idmap_suffix
|
222
|
+
retrieve_value_from_smb_conf(/ldap\s+idmap\s+suffix/i) || "ou=Idmap"
|
223
|
+
end
|
224
|
+
|
225
|
+
def start_uid
|
226
|
+
10000
|
227
|
+
end
|
228
|
+
|
229
|
+
def start_gid
|
230
|
+
10000
|
231
|
+
end
|
232
|
+
|
233
|
+
def default_user_gid
|
234
|
+
rid = ActiveSambaLdap::Group::DOMAIN_USERS_RID
|
235
|
+
ActiveSambaLdap::Group.rid2gid(rid)
|
236
|
+
end
|
237
|
+
|
238
|
+
def default_computer_gid
|
239
|
+
rid = ActiveSambaLdap::Group::DOMAIN_COMPUTERS_RID
|
240
|
+
ActiveSambaLdap::Group.rid2gid(rid)
|
241
|
+
end
|
242
|
+
|
243
|
+
def skeleton_directory
|
244
|
+
"/etc/skel"
|
245
|
+
end
|
246
|
+
|
247
|
+
def user_home_unc
|
248
|
+
netbios_name = self["samba_netbios_name"]
|
249
|
+
netbios_name ? "\\\\#{netbios_name}\\%U" : nil
|
250
|
+
end
|
251
|
+
|
252
|
+
def user_profile
|
253
|
+
netbios_name = self["samba_netbios_name"]
|
254
|
+
netbios_name ? "\\\\#{netbios_name}\\profiles\\%U" : nil
|
255
|
+
end
|
256
|
+
|
257
|
+
def user_home_directory
|
258
|
+
"/home/%U"
|
259
|
+
end
|
260
|
+
|
261
|
+
def user_home_directory_mode
|
262
|
+
0755
|
263
|
+
end
|
264
|
+
|
265
|
+
def normalize_user_home_directory_mode(mode)
|
266
|
+
if mode
|
267
|
+
Integer(mode)
|
268
|
+
else
|
269
|
+
nil
|
270
|
+
end
|
271
|
+
rescue ArgumentError
|
272
|
+
raise InvalidConfigurationValueError.new("user_home_directory",
|
273
|
+
mode, $!.message)
|
274
|
+
end
|
275
|
+
|
276
|
+
def user_login_shell
|
277
|
+
"/bin/false"
|
278
|
+
end
|
279
|
+
|
280
|
+
def user_home_drive
|
281
|
+
"H:"
|
282
|
+
end
|
283
|
+
|
284
|
+
def user_logon_script
|
285
|
+
"logon.bat"
|
286
|
+
end
|
287
|
+
|
288
|
+
def user_gecos
|
289
|
+
nil
|
290
|
+
end
|
291
|
+
|
292
|
+
def bind_dn
|
293
|
+
nil
|
294
|
+
end
|
295
|
+
|
296
|
+
def password_hash_type
|
297
|
+
:ssha
|
298
|
+
end
|
299
|
+
|
300
|
+
def normalize_password_hash_type(type)
|
301
|
+
type.to_s.downcase.to_sym
|
302
|
+
end
|
303
|
+
|
304
|
+
AVAILABLE_HASH_TYPES = [:crypt, :md5, :smd5, :sha, :ssha]
|
305
|
+
def validate_password_hash_type(type)
|
306
|
+
unless AVAILABLE_HASH_TYPES.include?(type)
|
307
|
+
types = AVAILABLE_HASH_TYPES.collect {|x| x.inspect}.join(", ")
|
308
|
+
raise InvalidConfigurationValueError.new("password_hash_type",
|
309
|
+
type,
|
310
|
+
_("must be in %s") % types)
|
311
|
+
end
|
312
|
+
end
|
313
|
+
|
314
|
+
private
|
315
|
+
def retrieve_value_from_smb_conf(key)
|
316
|
+
smb_conf = self['smb_conf']
|
317
|
+
if smb_conf and File.readable?(smb_conf)
|
318
|
+
line = File.read(smb_conf).grep(key).reject do |l|
|
319
|
+
/^\s*[#;]/ =~ l
|
320
|
+
end.first
|
321
|
+
if line
|
322
|
+
line.split(/=/, 2)[1].strip
|
323
|
+
else
|
324
|
+
nil
|
325
|
+
end
|
326
|
+
else
|
327
|
+
nil
|
328
|
+
end
|
329
|
+
end
|
330
|
+
end
|
331
|
+
end
|
332
|
+
end
|
333
|
+
end
|