ActiveSambaLdap 0.0.7

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.
Files changed (180) hide show
  1. data/NEWS.en +40 -0
  2. data/NEWS.ja +44 -0
  3. data/README.en +366 -0
  4. data/README.ja +361 -0
  5. data/Rakefile +168 -0
  6. data/bin/asl-groupadd +73 -0
  7. data/bin/asl-groupadd.help +1 -0
  8. data/bin/asl-groupdel +61 -0
  9. data/bin/asl-groupdel.help +1 -0
  10. data/bin/asl-groupmod +137 -0
  11. data/bin/asl-groupmod.help +1 -0
  12. data/bin/asl-groupshow +33 -0
  13. data/bin/asl-groupshow.help +1 -0
  14. data/bin/asl-passwd +90 -0
  15. data/bin/asl-passwd.help +1 -0
  16. data/bin/asl-populate +101 -0
  17. data/bin/asl-populate.help +1 -0
  18. data/bin/asl-purge +26 -0
  19. data/bin/asl-purge.help +1 -0
  20. data/bin/asl-samba-computeradd +96 -0
  21. data/bin/asl-samba-computeradd.help +1 -0
  22. data/bin/asl-samba-groupadd +57 -0
  23. data/bin/asl-samba-groupadd.help +1 -0
  24. data/bin/asl-samba-groupdel +55 -0
  25. data/bin/asl-samba-groupdel.help +1 -0
  26. data/bin/asl-samba-groupmod +99 -0
  27. data/bin/asl-samba-groupmod.help +1 -0
  28. data/bin/asl-samba-useradd +100 -0
  29. data/bin/asl-samba-useradd.help +1 -0
  30. data/bin/asl-samba-userdel +49 -0
  31. data/bin/asl-samba-userdel.help +1 -0
  32. data/bin/asl-samba-usermod +94 -0
  33. data/bin/asl-samba-usermod.help +1 -0
  34. data/bin/asl-useradd +264 -0
  35. data/bin/asl-useradd.help +1 -0
  36. data/bin/asl-userdel +84 -0
  37. data/bin/asl-userdel.help +1 -0
  38. data/bin/asl-usermod +335 -0
  39. data/bin/asl-usermod.help +1 -0
  40. data/bin/asl-usershow +33 -0
  41. data/bin/asl-usershow.help +1 -0
  42. data/lib/active_samba_ldap.rb +42 -0
  43. data/lib/active_samba_ldap/account_entry.rb +208 -0
  44. data/lib/active_samba_ldap/base.rb +137 -0
  45. data/lib/active_samba_ldap/command.rb +100 -0
  46. data/lib/active_samba_ldap/computer.rb +24 -0
  47. data/lib/active_samba_ldap/computer_account_entry.rb +34 -0
  48. data/lib/active_samba_ldap/configuration.rb +333 -0
  49. data/lib/active_samba_ldap/dc.rb +19 -0
  50. data/lib/active_samba_ldap/entry.rb +81 -0
  51. data/lib/active_samba_ldap/get_text_support.rb +12 -0
  52. data/lib/active_samba_ldap/group.rb +17 -0
  53. data/lib/active_samba_ldap/group_entry.rb +187 -0
  54. data/lib/active_samba_ldap/idmap.rb +19 -0
  55. data/lib/active_samba_ldap/ou.rb +20 -0
  56. data/lib/active_samba_ldap/populate.rb +257 -0
  57. data/lib/active_samba_ldap/reloadable.rb +15 -0
  58. data/lib/active_samba_ldap/samba_account_entry.rb +225 -0
  59. data/lib/active_samba_ldap/samba_entry.rb +26 -0
  60. data/lib/active_samba_ldap/samba_group_entry.rb +143 -0
  61. data/lib/active_samba_ldap/unix_id_pool.rb +43 -0
  62. data/lib/active_samba_ldap/user.rb +44 -0
  63. data/lib/active_samba_ldap/user_account_entry.rb +30 -0
  64. data/lib/active_samba_ldap/version.rb +3 -0
  65. data/lib/samba/encrypt.rb +86 -0
  66. data/misc/rd2html.rb +42 -0
  67. data/po/ja/active-samba-ldap.po +465 -0
  68. data/rails/README +30 -0
  69. data/rails/init.rb +33 -0
  70. data/rails_generators/scaffold_active_samba_ldap/scaffold_active_samba_ldap_generator.rb +27 -0
  71. data/rails_generators/scaffold_active_samba_ldap/templates/computer.rb +3 -0
  72. data/rails_generators/scaffold_active_samba_ldap/templates/dc.rb +3 -0
  73. data/rails_generators/scaffold_active_samba_ldap/templates/group.rb +3 -0
  74. data/rails_generators/scaffold_active_samba_ldap/templates/idmap.rb +3 -0
  75. data/rails_generators/scaffold_active_samba_ldap/templates/ldap.yml +24 -0
  76. data/rails_generators/scaffold_active_samba_ldap/templates/ou.rb +3 -0
  77. data/rails_generators/scaffold_active_samba_ldap/templates/samba_controller.rb +12 -0
  78. data/rails_generators/scaffold_active_samba_ldap/templates/samba_helper.rb +2 -0
  79. data/rails_generators/scaffold_active_samba_ldap/templates/samba_index.rhtml +17 -0
  80. data/rails_generators/scaffold_active_samba_ldap/templates/samba_populate.rhtml +15 -0
  81. data/rails_generators/scaffold_active_samba_ldap/templates/samba_purge.rhtml +10 -0
  82. data/rails_generators/scaffold_active_samba_ldap/templates/unix_id_pool.rb +3 -0
  83. data/rails_generators/scaffold_active_samba_ldap/templates/user.rb +3 -0
  84. data/setup.rb +1585 -0
  85. data/test-unit/History.txt +107 -0
  86. data/test-unit/README.txt +52 -0
  87. data/test-unit/Rakefile +40 -0
  88. data/test-unit/TODO +5 -0
  89. data/test-unit/bin/testrb +5 -0
  90. data/test-unit/lib/test/unit.rb +342 -0
  91. data/test-unit/lib/test/unit/assertionfailederror.rb +14 -0
  92. data/test-unit/lib/test/unit/assertions.rb +1149 -0
  93. data/test-unit/lib/test/unit/attribute.rb +125 -0
  94. data/test-unit/lib/test/unit/autorunner.rb +329 -0
  95. data/test-unit/lib/test/unit/collector.rb +43 -0
  96. data/test-unit/lib/test/unit/collector/descendant.rb +23 -0
  97. data/test-unit/lib/test/unit/collector/dir.rb +108 -0
  98. data/test-unit/lib/test/unit/collector/load.rb +135 -0
  99. data/test-unit/lib/test/unit/collector/objectspace.rb +34 -0
  100. data/test-unit/lib/test/unit/color-scheme.rb +86 -0
  101. data/test-unit/lib/test/unit/color.rb +96 -0
  102. data/test-unit/lib/test/unit/diff.rb +538 -0
  103. data/test-unit/lib/test/unit/error.rb +124 -0
  104. data/test-unit/lib/test/unit/exceptionhandler.rb +39 -0
  105. data/test-unit/lib/test/unit/failure.rb +110 -0
  106. data/test-unit/lib/test/unit/fixture.rb +176 -0
  107. data/test-unit/lib/test/unit/notification.rb +125 -0
  108. data/test-unit/lib/test/unit/omission.rb +143 -0
  109. data/test-unit/lib/test/unit/pending.rb +146 -0
  110. data/test-unit/lib/test/unit/priority.rb +181 -0
  111. data/test-unit/lib/test/unit/runner/console.rb +52 -0
  112. data/test-unit/lib/test/unit/runner/emacs.rb +8 -0
  113. data/test-unit/lib/test/unit/testcase.rb +425 -0
  114. data/test-unit/lib/test/unit/testresult.rb +89 -0
  115. data/test-unit/lib/test/unit/testsuite.rb +110 -0
  116. data/test-unit/lib/test/unit/ui/console/outputlevel.rb +14 -0
  117. data/test-unit/lib/test/unit/ui/console/testrunner.rb +223 -0
  118. data/test-unit/lib/test/unit/ui/emacs/testrunner.rb +49 -0
  119. data/test-unit/lib/test/unit/ui/testrunner.rb +20 -0
  120. data/test-unit/lib/test/unit/ui/testrunnermediator.rb +77 -0
  121. data/test-unit/lib/test/unit/ui/testrunnerutilities.rb +41 -0
  122. data/test-unit/lib/test/unit/util/backtracefilter.rb +41 -0
  123. data/test-unit/lib/test/unit/util/method-owner-finder.rb +28 -0
  124. data/test-unit/lib/test/unit/util/observable.rb +90 -0
  125. data/test-unit/lib/test/unit/util/procwrapper.rb +48 -0
  126. data/test-unit/lib/test/unit/version.rb +7 -0
  127. data/test-unit/sample/adder.rb +13 -0
  128. data/test-unit/sample/subtracter.rb +12 -0
  129. data/test-unit/sample/tc_adder.rb +18 -0
  130. data/test-unit/sample/tc_subtracter.rb +18 -0
  131. data/test-unit/sample/test_user.rb +22 -0
  132. data/test-unit/sample/ts_examples.rb +7 -0
  133. data/test-unit/test/collector/test-descendant.rb +135 -0
  134. data/test-unit/test/collector/test-load.rb +333 -0
  135. data/test-unit/test/collector/test_dir.rb +406 -0
  136. data/test-unit/test/collector/test_objectspace.rb +98 -0
  137. data/test-unit/test/run-test.rb +13 -0
  138. data/test-unit/test/test-attribute.rb +86 -0
  139. data/test-unit/test/test-color-scheme.rb +56 -0
  140. data/test-unit/test/test-color.rb +47 -0
  141. data/test-unit/test/test-diff.rb +477 -0
  142. data/test-unit/test/test-emacs-runner.rb +60 -0
  143. data/test-unit/test/test-fixture.rb +287 -0
  144. data/test-unit/test/test-notification.rb +33 -0
  145. data/test-unit/test/test-omission.rb +81 -0
  146. data/test-unit/test/test-pending.rb +70 -0
  147. data/test-unit/test/test-priority.rb +119 -0
  148. data/test-unit/test/test-testcase.rb +507 -0
  149. data/test-unit/test/test_assertions.rb +1082 -0
  150. data/test-unit/test/test_error.rb +26 -0
  151. data/test-unit/test/test_failure.rb +33 -0
  152. data/test-unit/test/test_testresult.rb +113 -0
  153. data/test-unit/test/test_testsuite.rb +129 -0
  154. data/test-unit/test/testunit-test-util.rb +14 -0
  155. data/test-unit/test/ui/test_testrunmediator.rb +20 -0
  156. data/test-unit/test/util/test-method-owner-finder.rb +38 -0
  157. data/test-unit/test/util/test_backtracefilter.rb +41 -0
  158. data/test-unit/test/util/test_observable.rb +102 -0
  159. data/test-unit/test/util/test_procwrapper.rb +36 -0
  160. data/test/asl-test-utils.rb +276 -0
  161. data/test/command.rb +67 -0
  162. data/test/config.yaml.sample +17 -0
  163. data/test/run-test.rb +20 -0
  164. data/test/test_asl_groupadd.rb +69 -0
  165. data/test/test_asl_groupdel.rb +88 -0
  166. data/test/test_asl_groupmod.rb +259 -0
  167. data/test/test_asl_groupshow.rb +21 -0
  168. data/test/test_asl_passwd.rb +126 -0
  169. data/test/test_asl_populate.rb +92 -0
  170. data/test/test_asl_purge.rb +21 -0
  171. data/test/test_asl_useradd.rb +712 -0
  172. data/test/test_asl_userdel.rb +75 -0
  173. data/test/test_asl_usermod.rb +549 -0
  174. data/test/test_asl_usershow.rb +27 -0
  175. data/test/test_entry.rb +21 -0
  176. data/test/test_group.rb +21 -0
  177. data/test/test_password.rb +51 -0
  178. data/test/test_samba_encrypt.rb +35 -0
  179. data/test/test_user_home_directory.rb +43 -0
  180. 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