activesambaldap 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (85) hide show
  1. data/NEWS.en +9 -0
  2. data/NEWS.ja +10 -0
  3. data/README.en +310 -0
  4. data/README.ja +307 -0
  5. data/Rakefile +95 -0
  6. data/bin/asl-groupadd +70 -0
  7. data/bin/asl-groupdel +58 -0
  8. data/bin/asl-groupmod +133 -0
  9. data/bin/asl-groupshow +31 -0
  10. data/bin/asl-passwd +99 -0
  11. data/bin/asl-populate +96 -0
  12. data/bin/asl-purge +24 -0
  13. data/bin/asl-samba-computeradd +94 -0
  14. data/bin/asl-samba-groupadd +55 -0
  15. data/bin/asl-samba-groupdel +53 -0
  16. data/bin/asl-samba-groupmod +98 -0
  17. data/bin/asl-samba-useradd +98 -0
  18. data/bin/asl-samba-userdel +47 -0
  19. data/bin/asl-samba-usermod +92 -0
  20. data/bin/asl-useradd +263 -0
  21. data/bin/asl-userdel +75 -0
  22. data/bin/asl-usermod +335 -0
  23. data/bin/asl-usershow +31 -0
  24. data/lib/active_samba_ldap/account.rb +199 -0
  25. data/lib/active_samba_ldap/base.rb +126 -0
  26. data/lib/active_samba_ldap/command.rb +94 -0
  27. data/lib/active_samba_ldap/computer.rb +13 -0
  28. data/lib/active_samba_ldap/computer_account.rb +34 -0
  29. data/lib/active_samba_ldap/configuration.rb +322 -0
  30. data/lib/active_samba_ldap/dc.rb +17 -0
  31. data/lib/active_samba_ldap/entry.rb +80 -0
  32. data/lib/active_samba_ldap/group.rb +182 -0
  33. data/lib/active_samba_ldap/idmap.rb +17 -0
  34. data/lib/active_samba_ldap/ou.rb +18 -0
  35. data/lib/active_samba_ldap/populate.rb +254 -0
  36. data/lib/active_samba_ldap/samba_account.rb +200 -0
  37. data/lib/active_samba_ldap/samba_computer.rb +20 -0
  38. data/lib/active_samba_ldap/samba_group.rb +126 -0
  39. data/lib/active_samba_ldap/samba_user.rb +39 -0
  40. data/lib/active_samba_ldap/unix_id_pool.rb +41 -0
  41. data/lib/active_samba_ldap/user.rb +14 -0
  42. data/lib/active_samba_ldap/user_account.rb +30 -0
  43. data/lib/active_samba_ldap/version.rb +3 -0
  44. data/lib/active_samba_ldap.rb +29 -0
  45. data/lib/samba/encrypt.rb +86 -0
  46. data/misc/rd2html.rb +42 -0
  47. data/rails/plugin/active_samba_ldap/README +30 -0
  48. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/scaffold_asl_generator.rb +28 -0
  49. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/computer.rb +3 -0
  50. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/dc.rb +3 -0
  51. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/group.rb +3 -0
  52. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/idmap.rb +3 -0
  53. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/ldap.yml +24 -0
  54. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/ou.rb +3 -0
  55. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_controller.rb +12 -0
  56. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_helper.rb +2 -0
  57. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_index.rhtml +17 -0
  58. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_populate.rhtml +15 -0
  59. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/samba_purge.rhtml +10 -0
  60. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/unix_id_pool.rb +3 -0
  61. data/rails/plugin/active_samba_ldap/generators/scaffold_asl/templates/user.rb +3 -0
  62. data/rails/plugin/active_samba_ldap/init.rb +6 -0
  63. data/test/asl-test-utils.rb +276 -0
  64. data/test/command.rb +64 -0
  65. data/test/config.yaml.sample +17 -0
  66. data/test/run-test.rb +18 -0
  67. data/test/test-unit-ext/always-show-result.rb +28 -0
  68. data/test/test-unit-ext/priority.rb +159 -0
  69. data/test/test-unit-ext.rb +2 -0
  70. data/test/test_asl_groupadd.rb +69 -0
  71. data/test/test_asl_groupdel.rb +88 -0
  72. data/test/test_asl_groupmod.rb +256 -0
  73. data/test/test_asl_groupshow.rb +21 -0
  74. data/test/test_asl_passwd.rb +125 -0
  75. data/test/test_asl_populate.rb +92 -0
  76. data/test/test_asl_purge.rb +21 -0
  77. data/test/test_asl_useradd.rb +710 -0
  78. data/test/test_asl_userdel.rb +73 -0
  79. data/test/test_asl_usermod.rb +541 -0
  80. data/test/test_asl_usershow.rb +27 -0
  81. data/test/test_group.rb +21 -0
  82. data/test/test_password.rb +51 -0
  83. data/test/test_samba_encrypt.rb +36 -0
  84. data/test/test_user_home_directory.rb +43 -0
  85. metadata +177 -0
@@ -0,0 +1,55 @@
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
+ unless Process.uid.zero?
19
+ $stderr.puts "need root authority."
20
+ exit 1
21
+ end
22
+
23
+ ActiveSambaLdap::Base.establish_connection("update")
24
+
25
+ class Group < ActiveSambaLdap::Group
26
+ ldap_mapping
27
+ end
28
+
29
+ class UnixIdPool < ActiveSambaLdap::UnixIdPool
30
+ ldap_mapping
31
+ end
32
+
33
+ if Group.exists?(name)
34
+ $stderr.puts "group '#{name}' already exists."
35
+ exit 1
36
+ end
37
+
38
+ create_options = {
39
+ :cn => name,
40
+ :gid_number => options.gid,
41
+ :pool_class => UnixIdPool,
42
+ :group_type => options.group_type,
43
+ }
44
+ group = Group.create(create_options)
45
+
46
+ unless group.errors.empty?
47
+ group.errors.each_full do |message|
48
+ $stderr.puts(message)
49
+ end
50
+ exit 1
51
+ end
52
+
53
+ ActiveSambaLdap::Base.restart_nscd
54
+
55
+ ActiveSambaLdap::Base.clear_active_connections!
@@ -0,0 +1,53 @@
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
+ unless Process.uid.zero?
19
+ $stderr.puts "need root authority."
20
+ exit 1
21
+ end
22
+
23
+ ActiveSambaLdap::Base.establish_connection("update")
24
+
25
+ class Group < ActiveSambaLdap::Group
26
+ ldap_mapping
27
+ end
28
+
29
+ class User < ActiveSambaLdap::User
30
+ ldap_mapping
31
+ end
32
+
33
+ class Computer < ActiveSambaLdap::Computer
34
+ ldap_mapping
35
+ end
36
+
37
+ unless Group.exists?(name)
38
+ $stderr.puts "group '#{name}' doesn't exist."
39
+ exit 1
40
+ end
41
+ group = Group.find(name)
42
+
43
+ begin
44
+ group.destroy(:remove_members => true,
45
+ :force_change_primary_members => options.force)
46
+ rescue ActiveSambaLdap::Error
47
+ $stderr.puts $!
48
+ exit 1
49
+ end
50
+
51
+ ActiveSambaLdap::Base.restart_nscd
52
+
53
+ ActiveSambaLdap::Base.clear_active_connections!
@@ -0,0 +1,98 @@
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.members_to_add = nil
8
+ options.members_to_delete = nil
9
+
10
+ opts.banner += " GROUP_NAME"
11
+
12
+ opts.on("-a", "--add-members=MEMBER1,MEMBER2,MEBMER3", Array,
13
+ "add members (comma delimited)") {|options.members_to_add|}
14
+ opts.on("-d", "--delete-members=MEMBER1,MEMBER2,MEBMER3", Array,
15
+ "delete members (comma delimited)") {|options.members_to_delete|}
16
+ end
17
+
18
+ name = nil
19
+ if argv.size == 1
20
+ name = argv.first
21
+ else
22
+ $stderr.puts opts
23
+ exit 1
24
+ end
25
+
26
+ unless Process.uid.zero?
27
+ $stderr.puts "need root authority."
28
+ exit 1
29
+ end
30
+
31
+ ActiveSambaLdap::Base.establish_connection("update")
32
+
33
+ class Group < ActiveSambaLdap::Group
34
+ ldap_mapping
35
+ end
36
+
37
+ class User < ActiveSambaLdap::User
38
+ ldap_mapping
39
+ end
40
+
41
+ class Computer < ActiveSambaLdap::Computer
42
+ ldap_mapping
43
+ end
44
+
45
+ unless Group.exists?(name)
46
+ $stderr.puts "group '#{name}' doesn't exist."
47
+ exit 1
48
+ end
49
+ group = Group.find(name)
50
+
51
+ if options.members_to_add and options.members_to_delete
52
+ duplicated_members = options.members_to_add & options.members_to_delete
53
+ unless duplicated_members.empty?
54
+ message = "there are duplicated members in adding and deleting members: "
55
+ message << duplicated_members.join(", ")
56
+ $stderr.puts message
57
+ exit 1
58
+ end
59
+ end
60
+
61
+ if options.members_to_add
62
+ users = []
63
+ computers = []
64
+ options.members_to_add.each do |member|
65
+ if /\$$/ =~ member
66
+ computers << Computer.find(member)
67
+ else
68
+ users << User.find(member)
69
+ end
70
+ end
71
+ group.users.concat(users)
72
+ group.computers.concat(computers)
73
+ end
74
+
75
+ if options.members_to_delete
76
+ users = []
77
+ computers = []
78
+ options.members_to_delete.each do |member|
79
+ if /\$$/ =~ member
80
+ computers << Computer.find(member)
81
+ else
82
+ users << User.find(member)
83
+ end
84
+ end
85
+ group.users -= users
86
+ group.computers -= computers
87
+ end
88
+
89
+ unless group.save
90
+ group.errors.each_full do |message|
91
+ $stderr.puts(message)
92
+ end
93
+ exit 1
94
+ end
95
+
96
+ ActiveSambaLdap::Base.restart_nscd
97
+
98
+ ActiveSambaLdap::Base.clear_active_connections!
@@ -0,0 +1,98 @@
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 += " USER_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
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 User.valid_name?(name)
55
+ $stderr.puts "'#{name}' is illegal user name"
56
+ exit 1
57
+ end
58
+
59
+ if User.exists?(name)
60
+ $stderr.puts "user '#{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
+ user = nil
70
+ begin
71
+ user = User.create(:uid => name, :group_class => Group)
72
+ rescue ActiveSambaLdap::UidNumberAlreadyExists
73
+ $stderr.puts "UID '#{uid_number}' already exists"
74
+ exit 1
75
+ rescue ActiveSambaLdap::GidNumberDoesNotExist,
76
+ ActiveSambaLdap::GroupDoesNotExist,
77
+ ActiveSambaLdap::GroupDoesNotHaveSambaSID
78
+ $stderr.puts $!
79
+ exit 1
80
+ end
81
+
82
+ unless user.errors.empty?
83
+ user.errors.each_full do |message|
84
+ $stderr.puts(message)
85
+ end
86
+ exit 1
87
+ end
88
+
89
+ begin
90
+ user.setup_home_directory
91
+ rescue SystemCallError
92
+ $stderr.puts $!
93
+ exit 1
94
+ end
95
+
96
+ ActiveSambaLdap::Base.restart_nscd
97
+
98
+ ActiveSambaLdap::Base.clear_active_connections!
@@ -0,0 +1,47 @@
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 += " USER_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
+ unless Process.uid.zero?
19
+ $stderr.puts "need root authority."
20
+ exit 1
21
+ end
22
+
23
+ ActiveSambaLdap::Base.establish_connection("update")
24
+
25
+ class User < ActiveSambaLdap::User
26
+ ldap_mapping
27
+ end
28
+
29
+ class Computer < ActiveSambaLdap::Computer
30
+ ldap_mapping
31
+ end
32
+
33
+ class Group < ActiveSambaLdap::Group
34
+ ldap_mapping
35
+ end
36
+
37
+ unless User.exists?(name)
38
+ $stderr.puts "user '#{name}' doesn't exist."
39
+ exit 1
40
+ end
41
+
42
+ user = User.find(name)
43
+ user.destroy(:removed_from_group => true, :remove_home_directory => true)
44
+
45
+ ActiveSambaLdap::Base.restart_nscd
46
+
47
+ ActiveSambaLdap::Base.clear_active_connections!
@@ -0,0 +1,92 @@
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.computer_account = false
8
+ options.gid = nil
9
+
10
+ opts.banner += " USER_NAME"
11
+
12
+ opts.on("-c", "--[no-]computer-account",
13
+ "is a Windows Workstation",
14
+ "(otherwise, Windows user)",
15
+ "(#{options.computer_account})") {|options.computer_account|}
16
+
17
+ opts.on("-g", "--gid=GID", "gid") {|options.gid|}
18
+ end
19
+
20
+ name = nil
21
+ if argv.size == 1
22
+ name = argv.first
23
+ else
24
+ $stderr.puts opts
25
+ exit 1
26
+ end
27
+
28
+ ActiveSambaLdap::Base.establish_connection("update")
29
+
30
+ class User < ActiveSambaLdap::User
31
+ ldap_mapping
32
+ end
33
+
34
+ class Computer < ActiveSambaLdap::Computer
35
+ ldap_mapping
36
+ end
37
+
38
+ class Group < ActiveSambaLdap::Group
39
+ ldap_mapping
40
+ end
41
+
42
+ options.computer_account = true if /\$$/ =~ name
43
+
44
+ member_class = options.computer_account ? Computer : User
45
+ member_type = member_class.name.downcase
46
+
47
+ if options.computer_account
48
+ name = name.chomp("$") + "$"
49
+ end
50
+
51
+ unless member_class.exists?(name)
52
+ $stderr.puts "#{member_type} '#{name}' doesn't exist."
53
+ exit 1
54
+ end
55
+ member = member_class.find(name)
56
+
57
+ unless Process.uid.zero?
58
+ password = ActiveSambaLdap::Command.read_password("Enter your password: ")
59
+
60
+ auth_class = Class.new(ActiveSambaLdap::Base)
61
+ config = ActiveSambaLdap::Base.configurations["reference"]
62
+ begin
63
+ auth_class.establish_connection(config.merge(:bind_dn => member.dn,
64
+ :password => password,
65
+ :allow_anonymous => false))
66
+ rescue ActiveLdap::AuthenticationError
67
+ $stderr.puts "password isn't match"
68
+ exit 1
69
+ ensure
70
+ auth_class.remove_connection
71
+ end
72
+ end
73
+
74
+ if options.gid
75
+ begin
76
+ member.primary_group = Group.find_by_name_or_gid_number(options.gid)
77
+ rescue ActiveSambaLdap::Error
78
+ $stderr.puts $!.message
79
+ exit 1
80
+ end
81
+ end
82
+
83
+ unless member.save
84
+ member.errors.each_full do |message|
85
+ $stderr.puts(message)
86
+ end
87
+ exit 1
88
+ end
89
+
90
+ ActiveSambaLdap::Base.restart_nscd
91
+
92
+ ActiveSambaLdap::Base.clear_active_connections!
data/bin/asl-useradd ADDED
@@ -0,0 +1,263 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'time'
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.ou = nil
10
+ options.computer_account = false
11
+ options.uid = nil
12
+ options.gid = nil
13
+ options.supplementary_groups = []
14
+ options.create_group = true
15
+ options.home_directory = nil
16
+ options.home_directory_mode = nil
17
+ options.shell = nil
18
+ options.comment = nil
19
+ options.setup_home_directory = true
20
+ options.skeleton_directory = nil
21
+ options.time = 0
22
+
23
+ options.expire_date = nil
24
+ options.can_change_password = nil
25
+ options.must_change_password = nil
26
+ options.samba_home_unc = nil
27
+ options.samba_home_drive = nil
28
+ options.samba_logon_script = nil
29
+ options.samba_profile_path = nil
30
+ options.samba_account_flags = nil
31
+ options.canonical_name = nil
32
+ options.given_name = nil
33
+ options.surname = nil
34
+ options.mail_addresses = nil
35
+ options.mail_to_addresses = nil
36
+
37
+ opts.banner += " USER_NAME"
38
+
39
+ opts.on("-o", "--ou=OU",
40
+ "add the user in the organizational unit OU",
41
+ "(relative to the user suffix)") do |ou|
42
+ if /^ou=/ =~ ou
43
+ options.ou = ou
44
+ else
45
+ options.ou = "ou=#{ou}"
46
+ end
47
+ end
48
+ opts.on("-c", "--[no-]computer-account",
49
+ "is a Windows Workstation",
50
+ "(otherwise, Windows user)",
51
+ "(#{options.computer_account})") {|options.computer_account|}
52
+ opts.on("-u", "--uid=UID", Integer, "uid") {|options.uid|}
53
+ opts.on("-g", "--gid=GID", "gid") {|options.gid|}
54
+ opts.on("-G", "--groups=GID1,GID2,GID3", Array,
55
+ "supplementary groups (comma separated)") do |groups|
56
+ options.supplementary_groups = groups
57
+ end
58
+ opts.on("--[no-]create-group",
59
+ "create a group for the user",
60
+ "(#{options.create_group})") {|options.create_group|}
61
+ opts.on("-c", "--comment=COMMENT",
62
+ "set the GECOS field for the new user account") {|options.comment|}
63
+ opts.on("-s", "--shell=SHELL", "shell") {|options.shell|}
64
+ opts.on("-G", "--given-name=NAME", "given name") {|options.given_name|}
65
+ opts.on("-N", "--canonical-name=NAME",
66
+ "canonical name") {|options.canonical_name|}
67
+ opts.on("-S", "--surname=NAME", "surname") {|options.surname|}
68
+
69
+ opts.on("-d", "--home-directory=HOME_DIR",
70
+ "home directory") {|options.home_directory|}
71
+ opts.on("--home-directory-mode=MODE",
72
+ "permission of home directory") {|options.home_directory_mode|}
73
+ opts.on("--[no-]setup-home-directory",
74
+ "setup home directory",
75
+ "(#{options.setup_home_directory}") {|options.setup_home_directory|}
76
+ opts.on("-k", "--skel=DIR", "--skeleton-directory=DIR",
77
+ "skeleton directory") {|options.skeleton_directory|}
78
+
79
+ opts.on("--time=TIME", Integer,
80
+ "wait TIME seconds before exiting",
81
+ "(#{options.time})") {|options.time|}
82
+
83
+ opts.separator("")
84
+ opts.separator("For samba accounts:")
85
+
86
+ opts.on("-e", "--expire-date=DATE", "expire date") do |date|
87
+ options.expire_date = Time.parse(date)
88
+ end
89
+ opts.on("-C", "--[no-]can-change-password",
90
+ "can change password") do |bool|
91
+ options.can_change_password = bool
92
+ end
93
+ opts.on("-M", "--[no-]must-change-password",
94
+ "must change password") do |bool|
95
+ options.must_change_password = bool
96
+ end
97
+ opts.on("--samba-home-path=UNC",
98
+ "sambaHomePath",
99
+ "(SMB home share, like '\\\\PDC\\user'") do |unc|
100
+ options.samba_home_unc = unc
101
+ end
102
+ opts.on("--samba-home-drive=DRIVE",
103
+ "sambaHomeDrive",
104
+ "(letter associated with home share,",
105
+ " like 'H:')") do |drive|
106
+ options.samba_home_drive = drive
107
+ end
108
+ opts.on("--samba-logon-script=SCRIPT",
109
+ "sambaLogonScript",
110
+ "(DOS script to execute on login)") do |script|
111
+ options.samba_logon_script = script
112
+ end
113
+ opts.on("--samba-profile-path=PATH",
114
+ "sambaProfilePath",
115
+ "(profile directory,",
116
+ " like '\\\\PDC\\profiles\\user')") do |path|
117
+ options.samba_profile_path = path
118
+ end
119
+ opts.on("--samba-account-flags=FLAGS",
120
+ "sambaAcctFlags",
121
+ "(samba account control bits,",
122
+ " like '[NDHTUMWSLXI]')") {|options.samba_account_flags|}
123
+
124
+ # opts.on("--mail-addresses=ADDRESS1,ADDRESS2,ADDRESS3",
125
+ # Array,
126
+ # "mailAddresses (comma separated)") {|options.mail_addresses|}
127
+ # opts.on("--mail-to-addresses=ADDRESS1,ADDRESS2,ADDRESS3",
128
+ # Array,
129
+ # "mailToAddresses (forward address)",
130
+ # "(comma separated)") do |addresses|
131
+ # options.mail_to_addresses = addresses
132
+ # end
133
+ end
134
+
135
+ name = nil
136
+ if argv.size == 1
137
+ name = argv.first
138
+ else
139
+ $stderr.puts opts
140
+ exit 1
141
+ end
142
+
143
+ unless Process.uid.zero?
144
+ $stderr.puts "need root authority."
145
+ exit 1
146
+ end
147
+
148
+ ActiveSambaLdap::Base.establish_connection("update")
149
+
150
+
151
+ class User < ActiveSambaLdap::SambaUser
152
+ ldap_mapping
153
+ end
154
+
155
+ class Computer < ActiveSambaLdap::SambaComputer
156
+ ldap_mapping
157
+ end
158
+
159
+ class Group < ActiveSambaLdap::SambaGroup
160
+ ldap_mapping
161
+ end
162
+
163
+ class UnixIdPool < ActiveSambaLdap::UnixIdPool
164
+ ldap_mapping
165
+ end
166
+
167
+ member_class = options.computer_account ? Computer : User
168
+
169
+ member_type = member_class.name.downcase
170
+
171
+ if options.computer_account
172
+ name = name.chomp("$") + "$"
173
+ end
174
+
175
+ unless member_class.valid_name?(name)
176
+ $stderr.puts "'#{name}' is illegal #{member_type} name"
177
+ exit 1
178
+ end
179
+
180
+ if member_class.exists?(name)
181
+ $stderr.puts "#{member_type} '#{name}' already exists."
182
+ exit 1
183
+ end
184
+
185
+ create_options = {
186
+ :uid => [name, options.ou].compact.join(","),
187
+ :uid_number => options.uid,
188
+ :gid_number => options.gid,
189
+ :create_group => options.create_group,
190
+ :group_class => Group,
191
+ :home_directory => options.home_directory,
192
+ :login_shell => options.shell,
193
+ :given_name => options.given_name,
194
+ :cn => options.canonical_name,
195
+ :sn => options.surname,
196
+ :gecos => options.comment,
197
+ :samba_acct_flags => options.samba_account_flags,
198
+ }
199
+
200
+ if !create_options[:cn] and options.given_name and options.surname
201
+ create_options[:cn] = "#{options.given_name} #{options.surname}"
202
+ end
203
+
204
+ if options.computer_account
205
+ create_options[:description] = "Computer"
206
+ create_options[:gecos] ||= "Computer"
207
+ else
208
+ create_options.merge!(:can_change_password => options.can_change_password,
209
+ :must_change_password => options.must_change_password,
210
+ :user_logon_script => options.samba_logon_script,
211
+ :user_home_unc => options.samba_home_unc,
212
+ :user_home_drive => options.samba_home_drive,
213
+ :user_profile => options.samba_profile_path)
214
+ if options.expire_date
215
+ create_options[:samba_kickoff_time] = options.expire_date.to_i.to_s
216
+ end
217
+ end
218
+
219
+ member = nil
220
+ begin
221
+ member = member_class.create(create_options)
222
+ rescue ActiveSambaLdap::UidNumberAlreadyExists
223
+ $stderr.puts "UID '#{uid_number}' already exists"
224
+ exit 1
225
+ rescue ActiveSambaLdap::GidNumberDoesNotExist,
226
+ ActiveSambaLdap::GroupDoesNotExist,
227
+ ActiveSambaLdap::GroupDoesNotHaveSambaSID
228
+ $stderr.puts $!
229
+ exit 1
230
+ end
231
+
232
+ unless member.errors.empty?
233
+ member.errors.each_full do |message|
234
+ $stderr.puts(message)
235
+ end
236
+ exit 1
237
+ end
238
+
239
+ if options.setup_home_directory
240
+ begin
241
+ setup_options = {
242
+ :mode => options.home_directory_mode,
243
+ :skeleton_directory => options.skeleton_directory,
244
+ }
245
+ member.setup_home_directory(setup_options)
246
+ rescue SystemCallError
247
+ $stderr.puts $!
248
+ exit 1
249
+ end
250
+ end
251
+
252
+ [member.gid_number, *options.supplementary_groups].each do |group|
253
+ group = Group.find_by_name_or_gid_number(group)
254
+ if options.computer_account
255
+ group.computers << member
256
+ else
257
+ group.users << member
258
+ end
259
+ end
260
+
261
+ ActiveSambaLdap::Base.restart_nscd
262
+
263
+ ActiveSambaLdap::Base.clear_active_connections!