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.
- 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 @@
|
|
1
|
+
|
data/bin/asl-usermod
ADDED
@@ -0,0 +1,335 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'time'
|
4
|
+
require 'fileutils'
|
5
|
+
|
6
|
+
require 'active_samba_ldap'
|
7
|
+
require 'active_samba_ldap/command'
|
8
|
+
|
9
|
+
include ActiveSambaLdap::GetTextSupport
|
10
|
+
|
11
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
12
|
+
options.computer_account = false
|
13
|
+
options.gecos = nil
|
14
|
+
options.home_directory = nil
|
15
|
+
options.move_home_directory = false
|
16
|
+
# options.inactive_days = nil
|
17
|
+
options.new_user_name = nil
|
18
|
+
options.uid = nil
|
19
|
+
options.allow_non_unique_uid_number = false
|
20
|
+
options.gid = nil
|
21
|
+
options.merge_groups = true
|
22
|
+
options.supplementary_groups = nil
|
23
|
+
options.shell = nil
|
24
|
+
options.given_name = nil
|
25
|
+
options.common_name = nil
|
26
|
+
options.surname = nil
|
27
|
+
|
28
|
+
options.expire_date = nil
|
29
|
+
options.can_change_password = nil
|
30
|
+
options.must_change_password = nil
|
31
|
+
options.samba_home_path = nil
|
32
|
+
options.samba_home_drive = nil
|
33
|
+
options.samba_logon_script = nil
|
34
|
+
options.samba_profile_path = nil
|
35
|
+
options.samba_account_flags = nil
|
36
|
+
options.enable = nil
|
37
|
+
options.mail_addresses = nil
|
38
|
+
options.mail_to_addresses = nil
|
39
|
+
|
40
|
+
|
41
|
+
opts.banner += " USER_NAME"
|
42
|
+
|
43
|
+
opts.on("-c", "--[no-]computer-account",
|
44
|
+
_("is a Windows Workstation"),
|
45
|
+
_("(otherwise, Windows user)"),
|
46
|
+
"(#{options.computer_account})") {|options.computer_account|}
|
47
|
+
|
48
|
+
opts.on("--gecos=GECOS", _("gecos")) {|options.gecos|}
|
49
|
+
opts.on("-d", "--home-directory=HOME_DIR",
|
50
|
+
_("home directory")) {|options.home_directory|}
|
51
|
+
opts.on("-m", "--[no-]move-home-directory",
|
52
|
+
_("move home directory"),
|
53
|
+
"(#{options.move_home_directory})") do |bool|
|
54
|
+
options.move_home_directory = bool
|
55
|
+
end
|
56
|
+
opts.on("-r", "--rename=NEW_NAME",
|
57
|
+
_("new user name (cn and dn are updated)")) do |name|
|
58
|
+
options.new_user_name = name
|
59
|
+
end
|
60
|
+
opts.on("-u", "--uid=UID", Integer, _("uid")) {|options.uid|}
|
61
|
+
opts.on("--[no-]allow-non-unique-uid",
|
62
|
+
_("uid can be non unique "),
|
63
|
+
"(#{options.allow_non_unique_uid_number})") do |bool|
|
64
|
+
options.allow_non_unique_uid_number = bool
|
65
|
+
end
|
66
|
+
opts.on("-g", "--gid=GID", "gid") {|options.gid|}
|
67
|
+
opts.on("-G", "--groups=GID1,GID2,GID3", Array,
|
68
|
+
_("supplementary groups (comma separated)")) do |groups|
|
69
|
+
options.supplementary_groups = groups
|
70
|
+
end
|
71
|
+
opts.on("--[no-]merge-groups",
|
72
|
+
_("replace supplementary groups "),
|
73
|
+
"(#{!options.merge_groups})") {|options.merge_groups|}
|
74
|
+
opts.on("-s", "--shell=SHELL", _("shell")) {|options.shell|}
|
75
|
+
opts.on("--given-name=NAME", _("given name")) {|options.given_name|}
|
76
|
+
opts.on("-N", "--common-name=NAME",
|
77
|
+
_("common name")) {|options.common_name|}
|
78
|
+
opts.on("-S", "--surname=NAME", _("surname")) {|options.surname|}
|
79
|
+
|
80
|
+
opts.separator("")
|
81
|
+
opts.separator(_("For samba accounts:"))
|
82
|
+
|
83
|
+
opts.on("-e", "--expire-date=DATE", _("expire date")) do |date|
|
84
|
+
options.expire_date = Time.parse(date)
|
85
|
+
end
|
86
|
+
opts.on("-C", "--[no-]can-change-password",
|
87
|
+
_("can change password")) do |bool|
|
88
|
+
options.can_change_password = bool
|
89
|
+
end
|
90
|
+
opts.on("-M", "--[no-]must-change-password",
|
91
|
+
_("must change password")) do |bool|
|
92
|
+
options.must_change_password = bool
|
93
|
+
end
|
94
|
+
opts.on("--samba-home-path=PATH",
|
95
|
+
_("sambaHomePath"),
|
96
|
+
_("(SMB home share, like '\\\\PDC\\user'")) do |path|
|
97
|
+
options.samba_home_path = path
|
98
|
+
end
|
99
|
+
opts.on("--samba-home-drive=DRIVE",
|
100
|
+
_("sambaHomeDrive"),
|
101
|
+
_("(letter associated with home share, like 'H:')")) do |drive|
|
102
|
+
options.samba_home_drive = drive
|
103
|
+
end
|
104
|
+
opts.on("--samba-logon-script=SCRIPT",
|
105
|
+
_("sambaLogonScript"),
|
106
|
+
_("(DOS script to execute on login)")) do |script|
|
107
|
+
options.samba_logon_script = script
|
108
|
+
end
|
109
|
+
opts.on("--samba-profile-path=PATH",
|
110
|
+
_("sambaProfilePath"),
|
111
|
+
_("(profile directory, " \
|
112
|
+
"like '\\\\PDC\\profiles\\user')")) do |path|
|
113
|
+
options.samba_profile_path = path
|
114
|
+
end
|
115
|
+
opts.on("--samba-account-flags=FLAGS",
|
116
|
+
_("sambaAcctFlags"),
|
117
|
+
_("(samba account control bits, " \
|
118
|
+
"like '[NDHTUMWSLXI]')")) {|options.samba_account_flags|}
|
119
|
+
opts.on("-D", "--[no-]disable-user", _("disable this user")) do |bool|
|
120
|
+
options.enable = !bool
|
121
|
+
end
|
122
|
+
opts.on("-E", "--[no-]enable-user", _("enable this user")) do |bool|
|
123
|
+
options.enable = bool
|
124
|
+
end
|
125
|
+
# opts.on("--mail-addresses=ADDRESS1,ADDRESS2,ADDRESS3",
|
126
|
+
# Array,
|
127
|
+
# _("mailAddresses (comma separated)")) {|options.mail_addresses|}
|
128
|
+
# opts.on("--mail-to-addresses=ADDRESS1,ADDRESS2,ADDRESS3",
|
129
|
+
# Array,
|
130
|
+
# _("mailToAddresses (forward address)"),
|
131
|
+
# _("(comma separated)")) do |addresses|
|
132
|
+
# options.mail_to_addresses = addresses
|
133
|
+
# end
|
134
|
+
end
|
135
|
+
|
136
|
+
name = nil
|
137
|
+
if argv.size == 1
|
138
|
+
name = argv.first
|
139
|
+
else
|
140
|
+
$stderr.puts opts
|
141
|
+
exit 1
|
142
|
+
end
|
143
|
+
|
144
|
+
ActiveSambaLdap::Base.setup_connection("update")
|
145
|
+
|
146
|
+
class User < ActiveSambaLdap::User
|
147
|
+
ldap_mapping
|
148
|
+
end
|
149
|
+
|
150
|
+
class Computer < ActiveSambaLdap::Computer
|
151
|
+
ldap_mapping
|
152
|
+
end
|
153
|
+
|
154
|
+
class Group < ActiveSambaLdap::Group
|
155
|
+
ldap_mapping
|
156
|
+
end
|
157
|
+
|
158
|
+
options.computer_account = true if /\$$/ =~ name
|
159
|
+
|
160
|
+
if options.computer_account
|
161
|
+
member_class = Computer
|
162
|
+
member_type = _("computer")
|
163
|
+
name = name.chomp("$") + "$"
|
164
|
+
else
|
165
|
+
member_class = User
|
166
|
+
member_type = _("user")
|
167
|
+
end
|
168
|
+
|
169
|
+
unless member_class.exists?(name)
|
170
|
+
$stderr.puts(_("%s doesn't exist: %s") % [member_type, name])
|
171
|
+
exit 1
|
172
|
+
end
|
173
|
+
member = member_class.find(name)
|
174
|
+
|
175
|
+
unless Process.uid.zero?
|
176
|
+
password = ActiveSambaLdap::Command.read_password(_("Enter your password: "))
|
177
|
+
|
178
|
+
begin
|
179
|
+
member.bind(password)
|
180
|
+
rescue ActiveLdap::AuthenticationError
|
181
|
+
$stderr.puts(_("password doesn't match."))
|
182
|
+
exit 1
|
183
|
+
end
|
184
|
+
member.remove_connection
|
185
|
+
end
|
186
|
+
|
187
|
+
if options.uid
|
188
|
+
begin
|
189
|
+
member.change_uid_number(options.uid, options.allow_non_unique_uid_number)
|
190
|
+
rescue ActiveSambaLdap::UidNumberAlreadyExists
|
191
|
+
$stderr.puts $!.message
|
192
|
+
exit 1
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
if options.gid
|
197
|
+
begin
|
198
|
+
member.primary_group = Group.find_by_name_or_gid_number(options.gid)
|
199
|
+
rescue ActiveSambaLdap::Error
|
200
|
+
$stderr.puts $!.message
|
201
|
+
exit 1
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
if options.shell
|
206
|
+
member.login_shell = options.shell
|
207
|
+
end
|
208
|
+
|
209
|
+
if options.gecos
|
210
|
+
member.gecos = options.gecos
|
211
|
+
member.description = options.gecos
|
212
|
+
member.display_name = options.gecos
|
213
|
+
end
|
214
|
+
|
215
|
+
if options.home_directory
|
216
|
+
if options.move_home_directory and !File.exist?(options.home_directory)
|
217
|
+
FileUtils.mv(member.home_directory, options.home_directory)
|
218
|
+
end
|
219
|
+
member.home_directory = options.home_directory
|
220
|
+
end
|
221
|
+
|
222
|
+
if options.common_name
|
223
|
+
member.cn = options.common_name
|
224
|
+
end
|
225
|
+
|
226
|
+
if options.surname
|
227
|
+
member.sn = options.surname
|
228
|
+
end
|
229
|
+
|
230
|
+
if options.given_name
|
231
|
+
member.given_name = options.given_name
|
232
|
+
end
|
233
|
+
|
234
|
+
if options.mail_addresses
|
235
|
+
raise _("not implemented.")
|
236
|
+
end
|
237
|
+
|
238
|
+
if options.mail_to_addresses
|
239
|
+
raise _("not implemented.")
|
240
|
+
end
|
241
|
+
|
242
|
+
if options.supplementary_groups
|
243
|
+
member.groups = [] unless options.merge_groups
|
244
|
+
member.groups = options.supplementary_groups.collect do |group|
|
245
|
+
begin
|
246
|
+
Group.find_by_name_or_gid_number(group)
|
247
|
+
rescue ActiveSambaLdap::GidNumberDoesNotExist
|
248
|
+
$stderr.puts $!
|
249
|
+
exit 1
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
if options.expire_date
|
255
|
+
member.samba_kickoff_time = options.expire_date.to_i.to_s
|
256
|
+
end
|
257
|
+
|
258
|
+
if options.samba_account_flags
|
259
|
+
member.samba_acct_flags = options.samba_account_flags
|
260
|
+
end
|
261
|
+
|
262
|
+
unless options.can_change_password.nil?
|
263
|
+
if options.can_change_password
|
264
|
+
member.enable_password_change
|
265
|
+
else
|
266
|
+
member.disable_password_change
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
unless options.must_change_password.nil?
|
271
|
+
if options.must_change_password
|
272
|
+
member.enable_forcing_password_change
|
273
|
+
else
|
274
|
+
member.disable_forcing_password_change
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
if options.samba_home_path
|
279
|
+
member.samba_home_path = options.samba_home_path
|
280
|
+
end
|
281
|
+
|
282
|
+
if options.samba_home_drive
|
283
|
+
member.samba_home_drive = options.samba_home_drive.sub(/([^:])$/, "\\1:")
|
284
|
+
end
|
285
|
+
|
286
|
+
if options.samba_logon_script
|
287
|
+
member.samba_logon_script = options.samba_logon_script
|
288
|
+
end
|
289
|
+
|
290
|
+
if options.samba_profile_path
|
291
|
+
member.samba_profile_path = options.samba_profile_path
|
292
|
+
end
|
293
|
+
|
294
|
+
unless options.enable.nil?
|
295
|
+
if options.enable
|
296
|
+
member.enable
|
297
|
+
else
|
298
|
+
member.disable
|
299
|
+
end
|
300
|
+
end
|
301
|
+
|
302
|
+
member.save!
|
303
|
+
|
304
|
+
if options.new_user_name
|
305
|
+
if options.computer_account
|
306
|
+
options.new_user_name = options.new_user_name.chomp("$") + "$"
|
307
|
+
end
|
308
|
+
if member_class.exists?(options.new_user_name)
|
309
|
+
format = _("%s already exists: %s")
|
310
|
+
$stderr.puts(format % [member_type, options.new_user_name])
|
311
|
+
exit 1
|
312
|
+
end
|
313
|
+
new_member = member_class.new(options.new_user_name)
|
314
|
+
|
315
|
+
new_member.cn = options.new_user_name
|
316
|
+
new_member.attributes = member.attributes.reject do |key, value|
|
317
|
+
%w(dn cn uid).include?(key)
|
318
|
+
end
|
319
|
+
new_member.save!
|
320
|
+
member.groups.each do |group|
|
321
|
+
if options.computer_account
|
322
|
+
group.computers -= [member]
|
323
|
+
group.computers << new_member
|
324
|
+
else
|
325
|
+
group.users -= [member]
|
326
|
+
group.users << new_member
|
327
|
+
end
|
328
|
+
end
|
329
|
+
|
330
|
+
member.destroy
|
331
|
+
end
|
332
|
+
|
333
|
+
ActiveSambaLdap::Base.restart_nscd
|
334
|
+
|
335
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
@@ -0,0 +1 @@
|
|
1
|
+
|
data/bin/asl-usershow
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'active_samba_ldap'
|
4
|
+
require 'active_samba_ldap/command'
|
5
|
+
|
6
|
+
include ActiveSambaLdap::GetTextSupport
|
7
|
+
|
8
|
+
argv, opts, options = ActiveSambaLdap::Command.parse_options do |opts, options|
|
9
|
+
opts.banner += " USER_NAME"
|
10
|
+
end
|
11
|
+
|
12
|
+
name = nil
|
13
|
+
if argv.size == 1
|
14
|
+
name = argv.first
|
15
|
+
else
|
16
|
+
$stderr.puts opts
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
ActiveSambaLdap::Base.setup_connection("reference")
|
21
|
+
|
22
|
+
class User < ActiveSambaLdap::User
|
23
|
+
ldap_mapping
|
24
|
+
end
|
25
|
+
|
26
|
+
unless User.exists?(name)
|
27
|
+
$stderr.puts(_("user doesn't exist: %s") % name)
|
28
|
+
exit 1
|
29
|
+
end
|
30
|
+
user = User.find(name)
|
31
|
+
puts user.to_ldif
|
32
|
+
|
33
|
+
ActiveSambaLdap::Base.clear_active_connections!
|
@@ -0,0 +1 @@
|
|
1
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require_gem_if_need = Proc.new do |library_name, gem_name, *options|
|
2
|
+
begin
|
3
|
+
require library_name
|
4
|
+
rescue LoadError
|
5
|
+
require 'rubygems'
|
6
|
+
gem gem_name, *options
|
7
|
+
require library_name
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
required_active_ldap_version = ">= 1.1.0"
|
12
|
+
require_gem_if_need.call("active_ldap", "activeldap",
|
13
|
+
required_active_ldap_version)
|
14
|
+
|
15
|
+
if ActiveSupport.const_defined?(:Dependencies)
|
16
|
+
dependencies = ActiveSupport::Dependencies
|
17
|
+
else
|
18
|
+
dependencies = Dependencies
|
19
|
+
end
|
20
|
+
|
21
|
+
if dependencies.respond_to?(:load_paths)
|
22
|
+
dependencies.load_paths << File.expand_path(File.dirname(__FILE__))
|
23
|
+
end
|
24
|
+
|
25
|
+
require 'active_samba_ldap/version'
|
26
|
+
require 'active_samba_ldap/get_text_support'
|
27
|
+
require 'active_samba_ldap/base'
|
28
|
+
require "active_samba_ldap/configuration"
|
29
|
+
require 'active_samba_ldap/populate'
|
30
|
+
|
31
|
+
ActiveSambaLdap::Base.class_eval do
|
32
|
+
include ActiveSambaLdap::Configuration
|
33
|
+
include ActiveSambaLdap::Populate
|
34
|
+
end
|
35
|
+
|
36
|
+
require 'active_samba_ldap/user'
|
37
|
+
require 'active_samba_ldap/group'
|
38
|
+
require 'active_samba_ldap/computer'
|
39
|
+
require 'active_samba_ldap/idmap'
|
40
|
+
require 'active_samba_ldap/unix_id_pool'
|
41
|
+
require 'active_samba_ldap/ou'
|
42
|
+
require 'active_samba_ldap/dc'
|
@@ -0,0 +1,208 @@
|
|
1
|
+
require 'time'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'English'
|
4
|
+
|
5
|
+
require 'active_samba_ldap/base'
|
6
|
+
|
7
|
+
module ActiveSambaLdap
|
8
|
+
module AccountEntry
|
9
|
+
NAME_RE_SRC = "(?!\\d)[\\w @_\\-\\.]+"
|
10
|
+
|
11
|
+
def self.included(base)
|
12
|
+
super
|
13
|
+
base.extend(ClassMethods)
|
14
|
+
end
|
15
|
+
|
16
|
+
module ClassMethods
|
17
|
+
def ldap_mapping(options={})
|
18
|
+
options = default_options.merge(options)
|
19
|
+
super(extract_ldap_mapping_options(options))
|
20
|
+
belongs_to :primary_group, primary_group_options(options)
|
21
|
+
belongs_to :groups, groups_options(options)
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_by_uid_number(number)
|
25
|
+
options = {:objects => true}
|
26
|
+
attribute = "uidNumber"
|
27
|
+
value = Integer(number)
|
28
|
+
find(:first, :filter => "(#{attribute}=#{value})")
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
def default_options
|
33
|
+
{
|
34
|
+
:dn_attribute => "uid",
|
35
|
+
:ldap_scope => :sub,
|
36
|
+
:primary_group_class => default_group_class,
|
37
|
+
:primary_group_foreign_key => "gidNumber",
|
38
|
+
:primary_group_primary_key => "gidNumber",
|
39
|
+
:groups_class => default_group_class,
|
40
|
+
:groups_many => "memberUid",
|
41
|
+
:prefix => default_prefix,
|
42
|
+
:classes => default_classes,
|
43
|
+
:recommended_classes => default_recommended_classes,
|
44
|
+
}
|
45
|
+
end
|
46
|
+
|
47
|
+
def default_group_class
|
48
|
+
"Group"
|
49
|
+
end
|
50
|
+
|
51
|
+
def default_classes
|
52
|
+
["top", "inetOrgPerson", "posixAccount"]
|
53
|
+
end
|
54
|
+
|
55
|
+
def default_recommended_classes
|
56
|
+
[]
|
57
|
+
end
|
58
|
+
|
59
|
+
def primary_group_options(options)
|
60
|
+
{
|
61
|
+
:class => options[:primary_group_class],
|
62
|
+
:foreign_key => options[:primary_group_foreign_key],
|
63
|
+
:primary_key => options[:primary_group_primary_key],
|
64
|
+
}
|
65
|
+
end
|
66
|
+
|
67
|
+
def groups_options(options)
|
68
|
+
{
|
69
|
+
:class => options[:groups_class],
|
70
|
+
:many => options[:groups_many],
|
71
|
+
}
|
72
|
+
end
|
73
|
+
|
74
|
+
def prepare_create_options(account, options)
|
75
|
+
prepare_create_options_for_number("uid_number", account, options)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def fill_default_values(options={})
|
80
|
+
self.cn ||= uid
|
81
|
+
self.sn ||= uid
|
82
|
+
self.given_name ||= uid
|
83
|
+
self.display_name ||= cn
|
84
|
+
self.gecos ||= substituted_value(:user_gecos) {cn}
|
85
|
+
self.home_directory ||= substituted_value(:user_home_directory)
|
86
|
+
self.login_shell ||= self.class.configuration[:user_login_shell]
|
87
|
+
|
88
|
+
options = options.stringify_keys
|
89
|
+
password = options["password"]
|
90
|
+
change_password(password) if password
|
91
|
+
self.user_password ||= "{crypt}x"
|
92
|
+
|
93
|
+
uid_number = options["uid_number"]
|
94
|
+
self.change_uid_number(uid_number) if uid_number
|
95
|
+
|
96
|
+
primary_group = options["group"] || retrieve_default_primary_group(options)
|
97
|
+
self.primary_group = primary_group if primary_group
|
98
|
+
|
99
|
+
self
|
100
|
+
end
|
101
|
+
|
102
|
+
def destroy(options={})
|
103
|
+
if options[:removed_from_group]
|
104
|
+
groups.each do |group|
|
105
|
+
remove_from_group(group)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
dir = home_directory
|
109
|
+
need_remove_home_directory =
|
110
|
+
options[:remove_home_directory] && !new_entry?
|
111
|
+
super()
|
112
|
+
if need_remove_home_directory and File.directory?(dir)
|
113
|
+
if options[:remove_home_directory_interactive]
|
114
|
+
system("rm", "-r", "-i", dir)
|
115
|
+
else
|
116
|
+
FileUtils.rm_r(dir)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
new_entry?
|
120
|
+
end
|
121
|
+
|
122
|
+
def change_uid_number(uid, allow_non_unique=false)
|
123
|
+
check_unique_uid_number(uid) unless allow_non_unique
|
124
|
+
self.uid_number = Integer(uid)
|
125
|
+
end
|
126
|
+
|
127
|
+
def change_password(password)
|
128
|
+
hash_type = self.class.configuration[:password_hash_type]
|
129
|
+
hashed_password = ActiveLdap::UserPassword.__send__(hash_type, password)
|
130
|
+
self.user_password = hashed_password
|
131
|
+
end
|
132
|
+
|
133
|
+
def setup_home_directory(options={})
|
134
|
+
dest = home_directory
|
135
|
+
return unless dest
|
136
|
+
|
137
|
+
FileUtils.mkdir_p(dest)
|
138
|
+
mode = options[:mode]
|
139
|
+
mode ||= self.class.configuration[:user_home_directory_mode]
|
140
|
+
FileUtils.chmod(Integer(mode), dest)
|
141
|
+
skel = options[:skeleton_directory]
|
142
|
+
skel ||= self.class.configuration[:skeleton_directory]
|
143
|
+
FileUtils.cp_r(Dir.glob(File.join(skel, ".*")) +
|
144
|
+
Dir.glob(File.join(skel, "*")) -
|
145
|
+
[File.join(skel, "."), File.join(skel, "..")],
|
146
|
+
dest)
|
147
|
+
FileUtils.chown_R(uid_number.to_s, gid_number.to_s, dest)
|
148
|
+
end
|
149
|
+
|
150
|
+
private
|
151
|
+
def check_unique_uid_number(uid_number)
|
152
|
+
ActiveSambaLdap::Base.restart_nscd do
|
153
|
+
if self.class.find_by_uid_number(uid_number)
|
154
|
+
raise UidNumberAlreadyExists.new(uid_number)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
def substitute_template(template)
|
160
|
+
template.gsub(/%U/, uid)
|
161
|
+
end
|
162
|
+
|
163
|
+
def substituted_value(key)
|
164
|
+
config = self.class.configuration
|
165
|
+
if block_given?
|
166
|
+
value = config[key.to_sym]
|
167
|
+
if value
|
168
|
+
substitute_template(value)
|
169
|
+
else
|
170
|
+
yield
|
171
|
+
end
|
172
|
+
else
|
173
|
+
substitute_template(config[key.to_sym])
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
def created_group_name
|
178
|
+
uid
|
179
|
+
end
|
180
|
+
|
181
|
+
def retrieve_default_primary_group(options={})
|
182
|
+
group = nil
|
183
|
+
|
184
|
+
gid_number = options["gid_number"]
|
185
|
+
group_class = options["group_class"]
|
186
|
+
group_class ||= self.class.associated_class(:primary_group)
|
187
|
+
unless gid_number
|
188
|
+
if options["create_group"]
|
189
|
+
group_name = created_group_name
|
190
|
+
if group_class.exists?(group_name)
|
191
|
+
group = group_class.find(group_name)
|
192
|
+
else
|
193
|
+
group = group_class.create(:cn => group_name,
|
194
|
+
:pool => options["pool"],
|
195
|
+
:pool_class => options["pool_class"])
|
196
|
+
end
|
197
|
+
else
|
198
|
+
gid_number = default_gid_number
|
199
|
+
end
|
200
|
+
end
|
201
|
+
if gid_number
|
202
|
+
group = group_class.find_by_gid_number(gid_number)
|
203
|
+
end
|
204
|
+
|
205
|
+
group
|
206
|
+
end
|
207
|
+
end
|
208
|
+
end
|