open_directory_utils 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -0
- data/lib/open_directory_utils/clean_check.rb +10 -0
- data/lib/open_directory_utils/commands_group.rb +85 -0
- data/lib/open_directory_utils/commands_user_attribs_ldap.rb +337 -0
- data/lib/open_directory_utils/{commands_user.rb → commands_user_attribs_od.rb} +13 -299
- data/lib/open_directory_utils/connection.rb +4 -2
- data/lib/open_directory_utils/version.rb +1 -1
- metadata +3 -3
- data/lib/open_directory_utils/user_command_pattern.rb +0 -188
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b950bf65b00895fca60d3f9e35cbc4777bc55760785bcfb2714762c4569e2126
|
4
|
+
data.tar.gz: 0302a96465860e72fd203f96c50d63fd675db9b49488e28e91fc2706105e5e98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 68c287fc687f3b4353c47b1805de579ed72670cec2c0b51ce25e8f3ad8625b86614a4f64bf1ca0312607d3db1a24c58dc7f108c3bbf9e5f37584368ac10c1649
|
7
|
+
data.tar.gz: 86e1a2d6dd44960e89ca2c5ebd3a8eababec75b575fc7c63cd4a4062bd976f4a33ef11b2cfdcf22753364aaff4bb5ecc461188d0596527c9f2273602d74f1f35
|
data/README.md
CHANGED
@@ -9,6 +9,20 @@ One can also build custom DSCL commands and send them to the server as needed to
|
|
9
9
|
|
10
10
|
* **v0.1.0** - 2018-06-06
|
11
11
|
- can adjust and delete OD attributes for users and groups (pre-built ldap attributes comming soon)
|
12
|
+
* **v0.1.1** - 2018-06-07
|
13
|
+
- refactored to separate OD attribute from LDAP attribute commands (shortened methods and better organization and shorter tests)
|
14
|
+
|
15
|
+
## ToDo
|
16
|
+
|
17
|
+
* LDAP attributes
|
18
|
+
* Verify setting Password
|
19
|
+
* Verify testing Password
|
20
|
+
* Refactor Process Results
|
21
|
+
* Test dscl direct commands
|
22
|
+
* Check Connection Unit Tests
|
23
|
+
* Learn dscl property names from LDAP
|
24
|
+
* Lock and unlock account authentication
|
25
|
+
* verify which email address is LDAP (& seen in GUI)
|
12
26
|
|
13
27
|
## Installation
|
14
28
|
|
@@ -26,5 +26,15 @@ module OpenDirectoryUtils
|
|
26
26
|
return user_attrs
|
27
27
|
end
|
28
28
|
|
29
|
+
def user_record_name_alternatives(attribs)
|
30
|
+
attribs[:record_name] = nil
|
31
|
+
attribs[:record_name] = attribs[:user_name]
|
32
|
+
attribs[:record_name] = attribs[:record_name] || attribs[:short_name]
|
33
|
+
attribs[:record_name] = attribs[:record_name] || attribs[:shortname]
|
34
|
+
attribs[:record_name] = attribs[:record_name] || attribs[:username]
|
35
|
+
attribs[:record_name] = attribs[:record_name] || attribs[:uid]
|
36
|
+
return attribs
|
37
|
+
end
|
38
|
+
|
29
39
|
end
|
30
40
|
end
|
@@ -38,6 +38,91 @@ module OpenDirectoryUtils
|
|
38
38
|
group_get_info(attribs, dir_info)
|
39
39
|
end
|
40
40
|
|
41
|
+
# add 1st user -- dscl . -read /Groups/ladmins
|
42
|
+
def user_in_group?(attribs, dir_info)
|
43
|
+
attribs = group_record_name_alternatives(attribs)
|
44
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
45
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
46
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
47
|
+
|
48
|
+
check_critical_attribute( attribs, :record_name, :groupname )
|
49
|
+
attribs = tidy_attribs(attribs)
|
50
|
+
|
51
|
+
command = {action: 'read', scope: 'Groups', attribute: nil, value: nil}
|
52
|
+
user_attrs = attribs.merge(command)
|
53
|
+
|
54
|
+
dscl( user_attrs, dir_info )
|
55
|
+
end
|
56
|
+
|
57
|
+
# http://krypted.com/mac-os-x/create-groups-using-dscl/
|
58
|
+
# https://superuser.com/questions/214004/how-to-add-user-to-a-group-from-mac-os-x-command-line?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
59
|
+
# sudo dseditgroup -o edit -a $username_to_add -t user admin
|
60
|
+
# sudo dseditgroup -o edit -a $username_to_add -t user wheel
|
61
|
+
# http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/
|
62
|
+
#
|
63
|
+
# add 1st user -- dscl . -create /Groups/ladmins GroupMembership localadmin
|
64
|
+
# add more users -- dscl . -append /Groups/ladmins GroupMembership 2ndlocaladmin
|
65
|
+
def user_first_in_group(attribs, dir_info)
|
66
|
+
attribs = group_record_name_alternatives(attribs)
|
67
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
68
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
69
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
70
|
+
|
71
|
+
attribs[:value] = attribs[:value] || attribs[:user_name]
|
72
|
+
attribs[:value] = attribs[:value] || attribs[:username]
|
73
|
+
attribs[:value] = attribs[:value] || attribs[:uid]
|
74
|
+
|
75
|
+
check_critical_attribute( attribs, :record_name, :groupname )
|
76
|
+
check_critical_attribute( attribs, :value, :username )
|
77
|
+
attribs = tidy_attribs(attribs)
|
78
|
+
|
79
|
+
command = {action: 'create', scope: 'Groups', attribute: 'GroupMembership'}
|
80
|
+
user_attrs = attribs.merge(command)
|
81
|
+
|
82
|
+
dscl( user_attrs, dir_info )
|
83
|
+
end
|
84
|
+
def user_append_to_group(attribs, dir_info)
|
85
|
+
attribs = group_record_name_alternatives(attribs)
|
86
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
87
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
88
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
89
|
+
|
90
|
+
attribs[:value] = attribs[:value] || attribs[:user_name]
|
91
|
+
attribs[:value] = attribs[:value] || attribs[:username]
|
92
|
+
attribs[:value] = attribs[:value] || attribs[:uid]
|
93
|
+
|
94
|
+
check_critical_attribute( attribs, :record_name, :groupname )
|
95
|
+
check_critical_attribute( attribs, :value, :username )
|
96
|
+
attribs = tidy_attribs(attribs)
|
97
|
+
|
98
|
+
command = {action: 'append', scope: 'Groups', attribute: 'GroupMembership'}
|
99
|
+
user_attrs = attribs.merge(command)
|
100
|
+
|
101
|
+
dscl( user_attrs, dir_info )
|
102
|
+
end
|
103
|
+
alias_method :user_add_to_group, :user_append_to_group
|
104
|
+
|
105
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -delete /Groups/$VALUE GroupMembership $shortname_USERNAME
|
106
|
+
def user_remove_from_group(attribs, dir_info)
|
107
|
+
attribs = group_record_name_alternatives(attribs)
|
108
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
109
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
110
|
+
# attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
111
|
+
|
112
|
+
attribs[:value] = attribs[:value] || attribs[:user_name]
|
113
|
+
attribs[:value] = attribs[:value] || attribs[:username]
|
114
|
+
attribs[:value] = attribs[:value] || attribs[:uid]
|
115
|
+
|
116
|
+
check_critical_attribute( attribs, :record_name, :groupname )
|
117
|
+
check_critical_attribute( attribs, :value, :username )
|
118
|
+
attribs = tidy_attribs(attribs)
|
119
|
+
|
120
|
+
command = {action: 'delete', scope: 'Groups', attribute: 'GroupMembership'}
|
121
|
+
user_attrs = attribs.merge(command)
|
122
|
+
|
123
|
+
dscl( user_attrs, dir_info )
|
124
|
+
end
|
125
|
+
|
41
126
|
# add 1st user -- dscl . create /Groups/ladmins GroupMembership localadmin
|
42
127
|
# add more users -- dscl . append /Groups/ladmins GroupMembership 2ndlocaladmin
|
43
128
|
def group_add_first_user(attribs, dir_info)
|
@@ -0,0 +1,337 @@
|
|
1
|
+
require "open_directory_utils/dscl"
|
2
|
+
require "open_directory_utils/clean_check"
|
3
|
+
|
4
|
+
module OpenDirectoryUtils
|
5
|
+
|
6
|
+
# this is a long list of pre-built dscl commands affecting users to accomplish common actions
|
7
|
+
# @note - these commands were derived from the following resrouces:
|
8
|
+
# * https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/dscl.1.html
|
9
|
+
# * https://superuser.com/questions/592921/mac-osx-users-vs-dscl-command-to-list-user/621055?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
10
|
+
module CommandsUserAttribsLdap
|
11
|
+
|
12
|
+
include OpenDirectoryUtils::Dscl
|
13
|
+
include OpenDirectoryUtils::CleanCheck
|
14
|
+
|
15
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER cn "$NAME"
|
16
|
+
def user_set_common_name(attribs, dir_info)
|
17
|
+
attribs = user_record_name_alternatives(attribs)
|
18
|
+
|
19
|
+
attribs[:value] = attribs[:value] || attribs[:cn]
|
20
|
+
attribs[:value] = attribs[:value] || attribs[:realname]
|
21
|
+
attribs[:value] = attribs[:value] || attribs[:real_name]
|
22
|
+
attribs[:value] = attribs[:value] || attribs[:fullname]
|
23
|
+
attribs[:value] = attribs[:value] || attribs[:full_name]
|
24
|
+
attribs[:value] = attribs[:value] || "#{attribs[:first_name]} #{attribs[:last_name]}"
|
25
|
+
|
26
|
+
check_critical_attribute( attribs, :record_name )
|
27
|
+
check_critical_attribute( attribs, :value, :common_name )
|
28
|
+
attribs = tidy_attribs(attribs)
|
29
|
+
|
30
|
+
command = {action: 'create', scope: 'Users', attribute: 'cn'}
|
31
|
+
user_attrs = attribs.merge(command)
|
32
|
+
|
33
|
+
dscl( user_attrs, dir_info )
|
34
|
+
end
|
35
|
+
alias_method :user_set_cn, :user_set_common_name
|
36
|
+
|
37
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME givenName "$VALUE"
|
38
|
+
def user_set_given_name(attribs, dir_info)
|
39
|
+
attribs = user_record_name_alternatives(attribs)
|
40
|
+
|
41
|
+
attribs[:value] = attribs[:value] || attribs[:given_name]
|
42
|
+
attribs[:value] = attribs[:value] || attribs[:first_name]
|
43
|
+
|
44
|
+
check_critical_attribute( attribs, :record_name )
|
45
|
+
check_critical_attribute( attribs, :value, :given_name )
|
46
|
+
attribs = tidy_attribs(attribs)
|
47
|
+
|
48
|
+
command = {action: 'create', scope: 'Users', attribute: 'givenName'}
|
49
|
+
user_attrs = attribs.merge(command)
|
50
|
+
|
51
|
+
dscl( user_attrs, dir_info )
|
52
|
+
end
|
53
|
+
|
54
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME sn "$VALUE"
|
55
|
+
def user_set_surname(attribs, dir_info)
|
56
|
+
attribs = user_record_name_alternatives(attribs)
|
57
|
+
|
58
|
+
attribs[:value] = attribs[:value] || attribs[:sn]
|
59
|
+
attribs[:value] = attribs[:value] || attribs[:surname]
|
60
|
+
attribs[:value] = attribs[:value] || attribs[:last_name]
|
61
|
+
|
62
|
+
check_critical_attribute( attribs, :record_name )
|
63
|
+
check_critical_attribute( attribs, :value, :surname )
|
64
|
+
attribs = tidy_attribs(attribs)
|
65
|
+
|
66
|
+
command = {action: 'create', scope: 'Users', attribute: 'sn'}
|
67
|
+
user_attrs = attribs.merge(command)
|
68
|
+
|
69
|
+
dscl( user_attrs, dir_info )
|
70
|
+
end
|
71
|
+
alias_method :user_set_sn, :user_set_surname
|
72
|
+
|
73
|
+
# # sudo dscl . -create /Users/someuser uidnumber "1010"
|
74
|
+
def user_set_uidnumber(attribs, dir_info)
|
75
|
+
attribs = user_record_name_alternatives(attribs)
|
76
|
+
|
77
|
+
attribs[:value] = attribs[:value] || attribs[:uniqueid]
|
78
|
+
attribs[:value] = attribs[:value] || attribs[:unique_id]
|
79
|
+
attribs[:value] = attribs[:value] || attribs[:uidnumber]
|
80
|
+
|
81
|
+
check_critical_attribute( attribs, :record_name )
|
82
|
+
check_critical_attribute( attribs, :value, :unique_id )
|
83
|
+
attribs = tidy_attribs(attribs)
|
84
|
+
|
85
|
+
command = {action: 'create', scope: 'Users', attribute: 'uidnumber'}
|
86
|
+
user_attrs = attribs.merge(command)
|
87
|
+
|
88
|
+
dscl( user_attrs, dir_info )
|
89
|
+
end
|
90
|
+
|
91
|
+
# sudo dscl . -create /Users/someuser PrimaryGroupID 80
|
92
|
+
def user_set_gidnumber(attribs, dir_info)
|
93
|
+
attribs = user_record_name_alternatives(attribs)
|
94
|
+
|
95
|
+
attribs[:value] = attribs[:value] || attribs[:group_id]
|
96
|
+
attribs[:value] = attribs[:value] || attribs[:gidnumber]
|
97
|
+
attribs[:value] = attribs[:value] || attribs[:group_number]
|
98
|
+
attribs[:value] = attribs[:value] || attribs[:primary_group_id]
|
99
|
+
|
100
|
+
check_critical_attribute( attribs, :record_name )
|
101
|
+
check_critical_attribute( attribs, :value, :group_id )
|
102
|
+
attribs = tidy_attribs(attribs)
|
103
|
+
|
104
|
+
command = {action: 'create', scope: 'Users', attribute: 'gidnumber'}
|
105
|
+
user_attrs = attribs.merge(command)
|
106
|
+
|
107
|
+
dscl( user_attrs, dir_info )
|
108
|
+
end
|
109
|
+
|
110
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME homedirectory "$VALUE"
|
111
|
+
def user_set_home_directory(attribs, dir_info)
|
112
|
+
attribs = user_record_name_alternatives(attribs)
|
113
|
+
|
114
|
+
attribs[:value] = attribs[:value] || attribs[:home_directory]
|
115
|
+
attribs[:value] = attribs[:value] || attribs[:nfs_home_directory]
|
116
|
+
attribs[:value] = attribs[:value] || '/Volumes/Macintosh HD/Users/someone'
|
117
|
+
|
118
|
+
command = {action: 'create', scope: 'Users', attribute: 'homedirectory'}
|
119
|
+
attribs = attribs.merge(command)
|
120
|
+
|
121
|
+
check_critical_attribute( attribs, :record_name )
|
122
|
+
check_critical_attribute( attribs, :value, :home_directory )
|
123
|
+
user_attrs = tidy_attribs(attribs)
|
124
|
+
|
125
|
+
dscl( user_attrs, dir_info )
|
126
|
+
end
|
127
|
+
|
128
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME loginShell "$VALUE"
|
129
|
+
def user_set_login_shell(attribs, dir_info)
|
130
|
+
attribs = user_record_name_alternatives(attribs)
|
131
|
+
|
132
|
+
attribs[:value] = attribs[:value] || attribs[:user_shell]
|
133
|
+
attribs[:value] = attribs[:value] || attribs[:shell]
|
134
|
+
attribs[:value] = attribs[:value] || '/bin/bash'
|
135
|
+
|
136
|
+
check_critical_attribute( attribs, :record_name )
|
137
|
+
check_critical_attribute( attribs, :value, :shell )
|
138
|
+
attribs = tidy_attribs(attribs)
|
139
|
+
|
140
|
+
command = {action: 'create', scope: 'Users', attribute: 'loginShell'}
|
141
|
+
user_attrs = attribs.merge(command)
|
142
|
+
|
143
|
+
dscl( user_attrs, dir_info )
|
144
|
+
end
|
145
|
+
|
146
|
+
|
147
|
+
# OTHER FIELDS
|
148
|
+
#####################
|
149
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME mail "$VALUE"
|
150
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME email "$VALUE"
|
151
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME apple-user-mailattribute "$VALUE"
|
152
|
+
def user_set_first_email(attribs, dir_info)
|
153
|
+
attribs = user_record_name_alternatives(attribs)
|
154
|
+
|
155
|
+
attribs[:value] = attribs[:value] || attribs['apple-user-mailattribute']
|
156
|
+
attribs[:value] = attribs[:value] || attribs[:apple_user_mailattribute]
|
157
|
+
attribs[:value] = attribs[:value] || attribs[:email]
|
158
|
+
attribs[:value] = attribs[:value] || attribs[:mail]
|
159
|
+
|
160
|
+
check_critical_attribute( attribs, :record_name )
|
161
|
+
check_critical_attribute( attribs, :value, :email )
|
162
|
+
attribs = tidy_attribs(attribs)
|
163
|
+
|
164
|
+
answer = []
|
165
|
+
|
166
|
+
command = {action: 'create', scope: 'Users', attribute: 'mail'}
|
167
|
+
user_attrs = attribs.merge(command)
|
168
|
+
answer << dscl( user_attrs, dir_info )
|
169
|
+
|
170
|
+
command = {action: 'create', scope: 'Users', attribute: 'email'}
|
171
|
+
user_attrs = attribs.merge(command)
|
172
|
+
answer << dscl( user_attrs, dir_info )
|
173
|
+
|
174
|
+
command = {action: 'create', scope: 'Users', attribute: 'apple-user-mailattribute'}
|
175
|
+
user_attrs = attribs.merge(command)
|
176
|
+
answer << dscl( user_attrs, dir_info )
|
177
|
+
|
178
|
+
return answer
|
179
|
+
end
|
180
|
+
alias_method :user_set_email, :user_set_first_email
|
181
|
+
|
182
|
+
def user_append_email(attribs, dir_info)
|
183
|
+
attribs = user_record_name_alternatives(attribs)
|
184
|
+
|
185
|
+
attribs[:value] = attribs[:value] || attribs['apple-user-mailattribute']
|
186
|
+
attribs[:value] = attribs[:value] || attribs[:apple_user_mailattribute]
|
187
|
+
attribs[:value] = attribs[:value] || attribs[:email]
|
188
|
+
attribs[:value] = attribs[:value] || attribs[:mail]
|
189
|
+
|
190
|
+
check_critical_attribute( attribs, :record_name )
|
191
|
+
check_critical_attribute( attribs, :value, :email )
|
192
|
+
attribs = tidy_attribs(attribs)
|
193
|
+
|
194
|
+
answer = []
|
195
|
+
|
196
|
+
command = {action: 'append', scope: 'Users', attribute: 'mail'}
|
197
|
+
user_attrs = attribs.merge(command)
|
198
|
+
answer << dscl( user_attrs, dir_info )
|
199
|
+
|
200
|
+
command = {action: 'append', scope: 'Users', attribute: 'email'}
|
201
|
+
user_attrs = attribs.merge(command)
|
202
|
+
answer << dscl( user_attrs, dir_info )
|
203
|
+
|
204
|
+
return answer
|
205
|
+
end
|
206
|
+
|
207
|
+
# dscl . -delete /Users/yourUserName
|
208
|
+
# https://tutorialforlinux.com/2011/09/15/delete-users-and-groups-from-terminal/
|
209
|
+
def user_delete(attribs, dir_info)
|
210
|
+
attribs = user_record_name_alternatives(attribs)
|
211
|
+
|
212
|
+
check_critical_attribute( attribs, :record_name )
|
213
|
+
attribs = tidy_attribs(attribs)
|
214
|
+
|
215
|
+
command = {action: 'delete', scope: 'Users', value: nil, attribute: nil}
|
216
|
+
user_attrs = attribs.merge(command)
|
217
|
+
|
218
|
+
dscl( user_attrs, dir_info )
|
219
|
+
end
|
220
|
+
|
221
|
+
# https://images.apple.com/server/docs/Command_Line.pdf
|
222
|
+
# https://serverfault.com/questions/20702/how-do-i-create-user-accounts-from-the-terminal-in-mac-os-x-10-5?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
223
|
+
# https://superuser.com/questions/1154564/how-to-create-a-user-from-the-macos-command-line
|
224
|
+
def user_create_min(attribs, dir_info)
|
225
|
+
attribs = user_record_name_alternatives(attribs)
|
226
|
+
|
227
|
+
check_critical_attribute( attribs, :record_name )
|
228
|
+
attribs = tidy_attribs(attribs)
|
229
|
+
|
230
|
+
command = {action: 'create', scope: 'Users', value: nil, attribute: nil}
|
231
|
+
user_attrs = attribs.merge(command)
|
232
|
+
|
233
|
+
dscl( user_attrs, dir_info )
|
234
|
+
|
235
|
+
answer = []
|
236
|
+
attribs[:value] = nil
|
237
|
+
answer << dscl( user_attrs, dir_info )
|
238
|
+
attribs[:value] = nil
|
239
|
+
answer << user_set_password(attribs, dir_info)
|
240
|
+
attribs[:value] = nil
|
241
|
+
answer << user_set_real_name(attribs, dir_info)
|
242
|
+
|
243
|
+
return answer
|
244
|
+
end
|
245
|
+
|
246
|
+
# https://images.apple.com/server/docs/Command_Line.pdf
|
247
|
+
# https://serverfault.com/questions/20702/how-do-i-create-user-accounts-from-the-terminal-in-mac-os-x-10-5?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
248
|
+
# https://superuser.com/questions/1154564/how-to-create-a-user-from-the-macos-command-line
|
249
|
+
def user_create_full(attribs, dir_info)
|
250
|
+
attribs = user_record_name_alternatives(attribs)
|
251
|
+
|
252
|
+
check_critical_attribute( attribs, :record_name )
|
253
|
+
attribs = tidy_attribs(attribs).dup
|
254
|
+
|
255
|
+
answer = []
|
256
|
+
attribs[:value] = nil
|
257
|
+
answer << user_create_min(attribs, dir_info)
|
258
|
+
attribs[:value] = nil
|
259
|
+
answer << user_set_shell(attribs, dir_info)
|
260
|
+
attribs[:value] = nil
|
261
|
+
answer << user_set_first_name(attribs, dir_info)
|
262
|
+
attribs[:value] = nil
|
263
|
+
answer << user_set_last_name(attribs, dir_info)
|
264
|
+
attribs[:value] = nil
|
265
|
+
answer << user_set_unique_id(attribs, dir_info)
|
266
|
+
attribs[:value] = nil
|
267
|
+
answer << user_set_primary_group_id(attribs, dir_info)
|
268
|
+
attribs[:value] = nil
|
269
|
+
answer << user_set_nfs_home_directory(attribs, dir_info)
|
270
|
+
# skip email if non-sent
|
271
|
+
unless attribs[:email].nil? and attribs[:mail].nil? and attribs[:apple_user_mailattribute].nil?
|
272
|
+
attribs[:value] = nil
|
273
|
+
answer << user_set_email(attribs, dir_info)
|
274
|
+
end
|
275
|
+
|
276
|
+
return answer.flatten
|
277
|
+
end
|
278
|
+
|
279
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME mobile "$VALUE"
|
280
|
+
def user_set_mobile_phone
|
281
|
+
end
|
282
|
+
|
283
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME telephoneNumber "$VALUE"
|
284
|
+
def user_set_work_phone
|
285
|
+
end
|
286
|
+
|
287
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME homePhone "$VALUE"
|
288
|
+
def user_set_home_phone
|
289
|
+
end
|
290
|
+
|
291
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME title "$VALUE"
|
292
|
+
def user_set_title
|
293
|
+
end
|
294
|
+
|
295
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME departmentNumber "$VALUE"
|
296
|
+
def user_set_department
|
297
|
+
end
|
298
|
+
|
299
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME street "$VALUE"
|
300
|
+
def user_set_street
|
301
|
+
end
|
302
|
+
alias_method :las_set_dorm, :user_set_street
|
303
|
+
alias_method :las_set_housing, :user_set_street
|
304
|
+
|
305
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname l "$VALUE"
|
306
|
+
def user_set_city
|
307
|
+
end
|
308
|
+
alias_method :las_, :user_set_city
|
309
|
+
|
310
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME st "$VALUE"
|
311
|
+
def user_set_state
|
312
|
+
end
|
313
|
+
alias_method :las_cultural_trip, :user_set_state
|
314
|
+
|
315
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME postalCode "$VALUE"
|
316
|
+
def user_set_postcode
|
317
|
+
end
|
318
|
+
alias_method :las_faculty_family, :user_set_postcode
|
319
|
+
|
320
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER c "$VALUE"
|
321
|
+
def user_set_country
|
322
|
+
end
|
323
|
+
|
324
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME labeledURI "$VALUE"
|
325
|
+
def user_set_homepage
|
326
|
+
end
|
327
|
+
alias_method :user_set_webpage, :user_set_homepage
|
328
|
+
alias_method :las_enrollment_date, :user_set_homepage
|
329
|
+
alias_method :las_begin_date, :user_set_homepage
|
330
|
+
|
331
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER description "$NAME"
|
332
|
+
def user_set_comments
|
333
|
+
end
|
334
|
+
alias_method :user_set_description, :user_set_comments
|
335
|
+
|
336
|
+
end
|
337
|
+
end
|
@@ -7,21 +7,11 @@ module OpenDirectoryUtils
|
|
7
7
|
# @note - these commands were derived from the following resrouces:
|
8
8
|
# * https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/dscl.1.html
|
9
9
|
# * https://superuser.com/questions/592921/mac-osx-users-vs-dscl-command-to-list-user/621055?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
10
|
-
module
|
10
|
+
module CommandsUserAttribsOd
|
11
11
|
|
12
12
|
include OpenDirectoryUtils::Dscl
|
13
13
|
include OpenDirectoryUtils::CleanCheck
|
14
14
|
|
15
|
-
def user_record_name_alternatives(attribs)
|
16
|
-
attribs[:record_name] = nil
|
17
|
-
attribs[:record_name] = attribs[:user_name]
|
18
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:short_name]
|
19
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:shortname]
|
20
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:username]
|
21
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:uid]
|
22
|
-
return attribs
|
23
|
-
end
|
24
|
-
|
25
15
|
# GET INFO
|
26
16
|
##########
|
27
17
|
# get user record -- dscl . -read /Users/<username>
|
@@ -72,28 +62,6 @@ module OpenDirectoryUtils
|
|
72
62
|
|
73
63
|
dscl( user_attrs, dir_info )
|
74
64
|
end
|
75
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER cn "$NAME"
|
76
|
-
def user_set_common_name(attribs, dir_info)
|
77
|
-
attribs = user_record_name_alternatives(attribs)
|
78
|
-
|
79
|
-
attribs[:value] = attribs[:value] || attribs[:cn]
|
80
|
-
attribs[:value] = attribs[:value] || attribs[:realname]
|
81
|
-
attribs[:value] = attribs[:value] || attribs[:real_name]
|
82
|
-
attribs[:value] = attribs[:value] || attribs[:fullname]
|
83
|
-
attribs[:value] = attribs[:value] || attribs[:full_name]
|
84
|
-
attribs[:value] = attribs[:value] || "#{attribs[:first_name]} #{attribs[:last_name]}"
|
85
|
-
|
86
|
-
check_critical_attribute( attribs, :record_name )
|
87
|
-
check_critical_attribute( attribs, :value, :common_name )
|
88
|
-
attribs = tidy_attribs(attribs)
|
89
|
-
|
90
|
-
command = {action: 'create', scope: 'Users', attribute: 'cn'}
|
91
|
-
user_attrs = attribs.merge(command)
|
92
|
-
|
93
|
-
dscl( user_attrs, dir_info )
|
94
|
-
end
|
95
|
-
alias_method :user_set_cn, :user_set_common_name
|
96
|
-
|
97
65
|
|
98
66
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME FirstName "$VALUE"
|
99
67
|
def user_set_first_name(attribs, dir_info)
|
@@ -111,22 +79,6 @@ module OpenDirectoryUtils
|
|
111
79
|
|
112
80
|
dscl( user_attrs, dir_info )
|
113
81
|
end
|
114
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME givenName "$VALUE"
|
115
|
-
def user_set_given_name(attribs, dir_info)
|
116
|
-
attribs = user_record_name_alternatives(attribs)
|
117
|
-
|
118
|
-
attribs[:value] = attribs[:value] || attribs[:given_name]
|
119
|
-
attribs[:value] = attribs[:value] || attribs[:first_name]
|
120
|
-
|
121
|
-
check_critical_attribute( attribs, :record_name )
|
122
|
-
check_critical_attribute( attribs, :value, :given_name )
|
123
|
-
attribs = tidy_attribs(attribs)
|
124
|
-
|
125
|
-
command = {action: 'create', scope: 'Users', attribute: 'givenName'}
|
126
|
-
user_attrs = attribs.merge(command)
|
127
|
-
|
128
|
-
dscl( user_attrs, dir_info )
|
129
|
-
end
|
130
82
|
|
131
83
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME LastName "$VALUE"
|
132
84
|
def user_set_last_name(attribs, dir_info)
|
@@ -145,24 +97,6 @@ module OpenDirectoryUtils
|
|
145
97
|
|
146
98
|
dscl( user_attrs, dir_info )
|
147
99
|
end
|
148
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME sn "$VALUE"
|
149
|
-
def user_set_surname(attribs, dir_info)
|
150
|
-
attribs = user_record_name_alternatives(attribs)
|
151
|
-
|
152
|
-
attribs[:value] = attribs[:value] || attribs[:sn]
|
153
|
-
attribs[:value] = attribs[:value] || attribs[:surname]
|
154
|
-
attribs[:value] = attribs[:value] || attribs[:last_name]
|
155
|
-
|
156
|
-
check_critical_attribute( attribs, :record_name )
|
157
|
-
check_critical_attribute( attribs, :value, :surname )
|
158
|
-
attribs = tidy_attribs(attribs)
|
159
|
-
|
160
|
-
command = {action: 'create', scope: 'Users', attribute: 'sn'}
|
161
|
-
user_attrs = attribs.merge(command)
|
162
|
-
|
163
|
-
dscl( user_attrs, dir_info )
|
164
|
-
end
|
165
|
-
alias_method :user_set_sn, :user_set_surname
|
166
100
|
|
167
101
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME NameSuffix "$VALUE"
|
168
102
|
def user_set_name_suffix
|
@@ -171,8 +105,6 @@ module OpenDirectoryUtils
|
|
171
105
|
def user_set_apple_name_suffix
|
172
106
|
end
|
173
107
|
|
174
|
-
|
175
|
-
|
176
108
|
# sudo dscl . -create /Users/someuser UniqueID "1010"
|
177
109
|
def user_set_unique_id(attribs, dir_info)
|
178
110
|
attribs = user_record_name_alternatives(attribs)
|
@@ -193,24 +125,6 @@ module OpenDirectoryUtils
|
|
193
125
|
dscl( user_attrs, dir_info )
|
194
126
|
end
|
195
127
|
|
196
|
-
# # sudo dscl . -create /Users/someuser uidnumber "1010"
|
197
|
-
def user_set_uidnumber(attribs, dir_info)
|
198
|
-
attribs = user_record_name_alternatives(attribs)
|
199
|
-
|
200
|
-
attribs[:value] = attribs[:value] || attribs[:uniqueid]
|
201
|
-
attribs[:value] = attribs[:value] || attribs[:unique_id]
|
202
|
-
attribs[:value] = attribs[:value] || attribs[:uidnumber]
|
203
|
-
|
204
|
-
check_critical_attribute( attribs, :record_name )
|
205
|
-
check_critical_attribute( attribs, :value, :unique_id )
|
206
|
-
attribs = tidy_attribs(attribs)
|
207
|
-
|
208
|
-
command = {action: 'create', scope: 'Users', attribute: 'uidnumber'}
|
209
|
-
user_attrs = attribs.merge(command)
|
210
|
-
|
211
|
-
dscl( user_attrs, dir_info )
|
212
|
-
end
|
213
|
-
|
214
128
|
# sudo dscl . -create /Users/someuser PrimaryGroupID 80
|
215
129
|
def user_set_primary_group_id(attribs, dir_info)
|
216
130
|
attribs = user_record_name_alternatives(attribs)
|
@@ -230,24 +144,6 @@ module OpenDirectoryUtils
|
|
230
144
|
|
231
145
|
dscl( user_attrs, dir_info )
|
232
146
|
end
|
233
|
-
# sudo dscl . -create /Users/someuser PrimaryGroupID 80
|
234
|
-
def user_set_gidnumber(attribs, dir_info)
|
235
|
-
attribs = user_record_name_alternatives(attribs)
|
236
|
-
|
237
|
-
attribs[:value] = attribs[:value] || attribs[:group_id]
|
238
|
-
attribs[:value] = attribs[:value] || attribs[:gidnumber]
|
239
|
-
attribs[:value] = attribs[:value] || attribs[:group_number]
|
240
|
-
attribs[:value] = attribs[:value] || attribs[:primary_group_id]
|
241
|
-
|
242
|
-
check_critical_attribute( attribs, :record_name )
|
243
|
-
check_critical_attribute( attribs, :value, :group_id )
|
244
|
-
attribs = tidy_attribs(attribs)
|
245
|
-
|
246
|
-
command = {action: 'create', scope: 'Users', attribute: 'gidnumber'}
|
247
|
-
user_attrs = attribs.merge(command)
|
248
|
-
|
249
|
-
dscl( user_attrs, dir_info )
|
250
|
-
end
|
251
147
|
|
252
148
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/someuser NFSHomeDirectory /Users/someuser
|
253
149
|
def user_set_nfs_home_directory(attribs, dir_info)
|
@@ -266,23 +162,6 @@ module OpenDirectoryUtils
|
|
266
162
|
|
267
163
|
dscl( user_attrs, dir_info )
|
268
164
|
end
|
269
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME homedirectory "$VALUE"
|
270
|
-
def user_set_home_directory(attribs, dir_info)
|
271
|
-
attribs = user_record_name_alternatives(attribs)
|
272
|
-
|
273
|
-
attribs[:value] = attribs[:value] || attribs[:home_directory]
|
274
|
-
attribs[:value] = attribs[:value] || attribs[:nfs_home_directory]
|
275
|
-
attribs[:value] = attribs[:value] || '/Volumes/Macintosh HD/Users/someone'
|
276
|
-
|
277
|
-
command = {action: 'create', scope: 'Users', attribute: 'homedirectory'}
|
278
|
-
attribs = attribs.merge(command)
|
279
|
-
|
280
|
-
check_critical_attribute( attribs, :record_name )
|
281
|
-
check_critical_attribute( attribs, :value, :home_directory )
|
282
|
-
user_attrs = tidy_attribs(attribs)
|
283
|
-
|
284
|
-
dscl( user_attrs, dir_info )
|
285
|
-
end
|
286
165
|
|
287
166
|
# /usr/bin/pwpolicy -a diradmin -p "TopSecret" -u username -setpassword "AnotherSecret"
|
288
167
|
# /usr/bin/dscl -plist -u diradmin -P #{adminpw} /LDAPv3/127.0.0.1/ -passwd /Users/#{shortname} "#{passwd}"
|
@@ -336,27 +215,7 @@ module OpenDirectoryUtils
|
|
336
215
|
|
337
216
|
dscl( user_attrs, dir_info )
|
338
217
|
end
|
339
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME loginShell "$VALUE"
|
340
|
-
def user_set_login_shell(attribs, dir_info)
|
341
|
-
attribs = user_record_name_alternatives(attribs)
|
342
|
-
|
343
|
-
attribs[:value] = attribs[:value] || attribs[:user_shell]
|
344
|
-
attribs[:value] = attribs[:value] || attribs[:shell]
|
345
|
-
attribs[:value] = attribs[:value] || '/bin/bash'
|
346
|
-
|
347
|
-
check_critical_attribute( attribs, :record_name )
|
348
|
-
check_critical_attribute( attribs, :value, :shell )
|
349
|
-
attribs = tidy_attribs(attribs)
|
350
|
-
|
351
|
-
command = {action: 'create', scope: 'Users', attribute: 'loginShell'}
|
352
|
-
user_attrs = attribs.merge(command)
|
353
|
-
|
354
|
-
dscl( user_attrs, dir_info )
|
355
|
-
end
|
356
|
-
|
357
218
|
|
358
|
-
# OTHER FIELDS
|
359
|
-
#####################
|
360
219
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME mail "$VALUE"
|
361
220
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME email "$VALUE"
|
362
221
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME apple-user-mailattribute "$VALUE"
|
@@ -487,108 +346,13 @@ module OpenDirectoryUtils
|
|
487
346
|
return answer.flatten
|
488
347
|
end
|
489
348
|
|
490
|
-
# ADD USER TO GROUPS
|
491
|
-
#################### #
|
492
|
-
# add 1st user -- dscl . -read /Groups/ladmins
|
493
|
-
def user_in_group?(attribs, dir_info)
|
494
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
495
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
496
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
497
|
-
|
498
|
-
check_critical_attribute( attribs, :record_name, :groupname )
|
499
|
-
attribs = tidy_attribs(attribs)
|
500
|
-
|
501
|
-
command = {action: 'read', scope: 'Groups', attribute: nil, value: nil}
|
502
|
-
user_attrs = attribs.merge(command)
|
503
|
-
|
504
|
-
dscl( user_attrs, dir_info )
|
505
|
-
end
|
506
|
-
|
507
|
-
# http://krypted.com/mac-os-x/create-groups-using-dscl/
|
508
|
-
# https://superuser.com/questions/214004/how-to-add-user-to-a-group-from-mac-os-x-command-line?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
509
|
-
# sudo dseditgroup -o edit -a $username_to_add -t user admin
|
510
|
-
# sudo dseditgroup -o edit -a $username_to_add -t user wheel
|
511
|
-
# http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/
|
512
|
-
#
|
513
|
-
# add 1st user -- dscl . -create /Groups/ladmins GroupMembership localadmin
|
514
|
-
# add more users -- dscl . -append /Groups/ladmins GroupMembership 2ndlocaladmin
|
515
|
-
def user_first_in_group(attribs, dir_info)
|
516
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
517
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
518
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
519
|
-
|
520
|
-
attribs[:value] = attribs[:value] || attribs[:user_name]
|
521
|
-
attribs[:value] = attribs[:value] || attribs[:username]
|
522
|
-
attribs[:value] = attribs[:value] || attribs[:uid]
|
523
|
-
|
524
|
-
check_critical_attribute( attribs, :record_name, :groupname )
|
525
|
-
check_critical_attribute( attribs, :value, :username )
|
526
|
-
attribs = tidy_attribs(attribs)
|
527
|
-
|
528
|
-
command = {action: 'create', scope: 'Groups', attribute: 'GroupMembership'}
|
529
|
-
user_attrs = attribs.merge(command)
|
530
|
-
|
531
|
-
dscl( user_attrs, dir_info )
|
532
|
-
end
|
533
|
-
def user_append_to_group(attribs, dir_info)
|
534
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
535
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
536
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
537
|
-
|
538
|
-
attribs[:value] = attribs[:value] || attribs[:user_name]
|
539
|
-
attribs[:value] = attribs[:value] || attribs[:username]
|
540
|
-
attribs[:value] = attribs[:value] || attribs[:uid]
|
541
|
-
|
542
|
-
check_critical_attribute( attribs, :record_name, :groupname )
|
543
|
-
check_critical_attribute( attribs, :value, :username )
|
544
|
-
attribs = tidy_attribs(attribs)
|
545
|
-
|
546
|
-
command = {action: 'append', scope: 'Groups', attribute: 'GroupMembership'}
|
547
|
-
user_attrs = attribs.merge(command)
|
548
|
-
|
549
|
-
dscl( user_attrs, dir_info )
|
550
|
-
end
|
551
|
-
alias_method :user_add_to_group, :user_append_to_group
|
552
|
-
|
553
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -delete /Groups/$VALUE GroupMembership $shortname_USERNAME
|
554
|
-
def user_remove_from_group(attribs, dir_info)
|
555
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:group_name]
|
556
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
557
|
-
attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
558
|
-
|
559
|
-
attribs[:value] = attribs[:value] || attribs[:user_name]
|
560
|
-
attribs[:value] = attribs[:value] || attribs[:username]
|
561
|
-
attribs[:value] = attribs[:value] || attribs[:uid]
|
562
|
-
|
563
|
-
check_critical_attribute( attribs, :record_name, :groupname )
|
564
|
-
check_critical_attribute( attribs, :value, :username )
|
565
|
-
attribs = tidy_attribs(attribs)
|
566
|
-
|
567
|
-
command = {action: 'delete', scope: 'Groups', attribute: 'GroupMembership'}
|
568
|
-
user_attrs = attribs.merge(command)
|
569
|
-
|
570
|
-
dscl( user_attrs, dir_info )
|
571
|
-
end
|
572
|
-
|
573
349
|
# 1st keyword -- /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME apple-keyword "$VALUE"
|
574
350
|
# other keywords -- /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$shortname_USERNAME apple-keyword "$VALUE"
|
575
|
-
def
|
351
|
+
def user_set_first_keyword
|
576
352
|
end
|
577
353
|
|
578
354
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$shortname_USERNAME apple-keyword "$VALUE"
|
579
|
-
def
|
580
|
-
end
|
581
|
-
|
582
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME mobile "$VALUE"
|
583
|
-
def user_set_mobile_phone
|
584
|
-
end
|
585
|
-
|
586
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME telephoneNumber "$VALUE"
|
587
|
-
def user_set_work_phone
|
588
|
-
end
|
589
|
-
|
590
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME homePhone "$VALUE"
|
591
|
-
def user_set_home_phone
|
355
|
+
def user_append_keyword
|
592
356
|
end
|
593
357
|
|
594
358
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME apple-company "$VALUE"
|
@@ -596,38 +360,17 @@ module OpenDirectoryUtils
|
|
596
360
|
end
|
597
361
|
alias_method :las_program_info, :user_set_company
|
598
362
|
|
599
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -
|
604
|
-
def
|
605
|
-
end
|
606
|
-
|
607
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME street "$VALUE"
|
608
|
-
def user_set_street
|
609
|
-
end
|
610
|
-
alias_method :las_set_dorm, :user_set_street
|
611
|
-
alias_method :las_set_housing, :user_set_street
|
612
|
-
|
613
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname l "$VALUE"
|
614
|
-
def user_set_city
|
615
|
-
end
|
616
|
-
alias_method :las_, :user_set_city
|
617
|
-
|
618
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME st "$VALUE"
|
619
|
-
def user_set_state
|
620
|
-
end
|
621
|
-
alias_method :las_cultural_trip, :user_set_state
|
622
|
-
|
623
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME postalCode "$VALUE"
|
624
|
-
def user_set_postcode
|
625
|
-
end
|
626
|
-
alias_method :las_faculty_family, :user_set_postcode
|
627
|
-
|
628
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER c "$VALUE"
|
629
|
-
def user_set_country
|
363
|
+
# first - /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER apple-imhandle "$VALUE"
|
364
|
+
# others - /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$USER apple-imhandle "$VALUE"
|
365
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER apple-imhandle "AIM:created: $CREATE"
|
366
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$USER apple-imhandle "ICQ:start: $START"
|
367
|
+
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$USER apple-imhandle "MSN:end: $END"
|
368
|
+
def user_set_chat
|
630
369
|
end
|
370
|
+
alias_method :user_set_chat_channels, :user_set_chat
|
371
|
+
alias_method :las_created_date, :user_set_chat
|
372
|
+
alias_method :las_start_date, :user_set_chat
|
373
|
+
alias_method :las_end_date, :user_set_chat
|
631
374
|
|
632
375
|
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME apple-webloguri "$VALUE"
|
633
376
|
def user_set_blog
|
@@ -646,35 +389,6 @@ module OpenDirectoryUtils
|
|
646
389
|
end
|
647
390
|
alias_method :las_link_parent_to_student, :user_set_relationships
|
648
391
|
|
649
|
-
# first - /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER apple-imhandle "$VALUE"
|
650
|
-
# others - /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$USER apple-imhandle "$VALUE"
|
651
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER apple-imhandle "AIM:created: $CREATE"
|
652
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$USER apple-imhandle "ICQ:start: $START"
|
653
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$USER apple-imhandle "MSN:end: $END"
|
654
|
-
def user_set_chat
|
655
|
-
end
|
656
|
-
alias_method :user_set_chat_channels, :user_set_chat
|
657
|
-
alias_method :las_created_date, :user_set_chat
|
658
|
-
alias_method :las_start_date, :user_set_chat
|
659
|
-
alias_method :las_end_date, :user_set_chat
|
660
|
-
|
661
|
-
|
662
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$shortname_USERNAME labeledURI "$VALUE"
|
663
|
-
def user_set_homepage
|
664
|
-
end
|
665
|
-
alias_method :user_set_webpage, :user_set_homepage
|
666
|
-
alias_method :las_enrollment_date, :user_set_homepage
|
667
|
-
alias_method :las_begin_date, :user_set_homepage
|
668
|
-
|
669
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER description "$NAME"
|
670
|
-
def user_set_comments
|
671
|
-
end
|
672
|
-
alias_method :user_set_description, :user_set_comments
|
673
|
-
|
674
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$USER description "$NAME"
|
675
|
-
def user_comments
|
676
|
-
end
|
677
|
-
alias_method :user_description, :user_comments
|
678
392
|
|
679
393
|
end
|
680
394
|
end
|
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'net/ssh'
|
2
2
|
require "open_directory_utils/dscl"
|
3
3
|
require "open_directory_utils/pwpolicy"
|
4
|
-
require "open_directory_utils/commands_user"
|
5
4
|
require "open_directory_utils/commands_group"
|
5
|
+
require "open_directory_utils/commands_user_attribs_od"
|
6
|
+
require "open_directory_utils/commands_user_attribs_ldap"
|
6
7
|
|
7
8
|
module OpenDirectoryUtils
|
8
9
|
class Connection
|
@@ -11,8 +12,9 @@ module OpenDirectoryUtils
|
|
11
12
|
|
12
13
|
include OpenDirectoryUtils::Dscl
|
13
14
|
include OpenDirectoryUtils::Pwpolicy
|
14
|
-
include OpenDirectoryUtils::CommandsUser
|
15
15
|
include OpenDirectoryUtils::CommandsGroup
|
16
|
+
include OpenDirectoryUtils::CommandsUserAttribsOd
|
17
|
+
include OpenDirectoryUtils::CommandsUserAttribsLdap
|
16
18
|
|
17
19
|
# configure connection with ENV_VARS (or parameters)
|
18
20
|
# @params [Hash] - reqiured info includes: srv_hostname:, srv_username: (password: if not using ssh-keys)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_directory_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bill Tihen
|
@@ -89,11 +89,11 @@ files:
|
|
89
89
|
- lib/open_directory_utils.rb
|
90
90
|
- lib/open_directory_utils/clean_check.rb
|
91
91
|
- lib/open_directory_utils/commands_group.rb
|
92
|
-
- lib/open_directory_utils/
|
92
|
+
- lib/open_directory_utils/commands_user_attribs_ldap.rb
|
93
|
+
- lib/open_directory_utils/commands_user_attribs_od.rb
|
93
94
|
- lib/open_directory_utils/connection.rb
|
94
95
|
- lib/open_directory_utils/dscl.rb
|
95
96
|
- lib/open_directory_utils/pwpolicy.rb
|
96
|
-
- lib/open_directory_utils/user_command_pattern.rb
|
97
97
|
- lib/open_directory_utils/version.rb
|
98
98
|
- open_directory_utils.gemspec
|
99
99
|
homepage: https://github.com/btihen/open_directory_utils
|
@@ -1,188 +0,0 @@
|
|
1
|
-
module OpenDirectoryUtils
|
2
|
-
# command pattern
|
3
|
-
# https://makandracards.com/alexander-m/43748-command-pattern
|
4
|
-
# https://stackoverflow.com/questions/43535421/command-pattern-in-ruby?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
5
|
-
#
|
6
|
-
# DSCL
|
7
|
-
# https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/dscl.1.html
|
8
|
-
# https://superuser.com/questions/592921/mac-osx-users-vs-dscl-command-to-list-user/621055?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
9
|
-
class Commands
|
10
|
-
class Error < StandardError; end
|
11
|
-
|
12
|
-
def initialize(params)
|
13
|
-
end
|
14
|
-
|
15
|
-
def execute
|
16
|
-
raise NotYetImplemented
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
# # get all usernames -- dscl . -list /Users
|
21
|
-
# # get all user details -- dscl . -readall /Users
|
22
|
-
# def user_exists?
|
23
|
-
# end
|
24
|
-
class UserGetInfo
|
25
|
-
# get user record -- dscl . -read /Users/<username>
|
26
|
-
# get user value -- dscl . -read /Users/<username> <key>
|
27
|
-
# search od user -- dscl . -search /Users RealName "Andrew Garrett"
|
28
|
-
# return as xml -- dscl -plist . -search /Users RealName "Andrew Garrett"
|
29
|
-
def user_get_info
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
# https://images.apple.com/server/docs/Command_Line.pdf
|
34
|
-
# https://serverfault.com/questions/20702/how-do-i-create-user-accounts-from-the-terminal-in-mac-os-x-10-5?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
35
|
-
# https://superuser.com/questions/1154564/how-to-create-a-user-from-the-macos-command-line
|
36
|
-
# There are a few steps to create a user account from the command line. The good news is that you're using the right tool, dscl. What you're missing are the separate components that comprise a user account. You have to create these manually.
|
37
|
-
# sudo dscl . -create /Users/someuser
|
38
|
-
# sudo dscl . -create /Users/someuser UserShell /bin/bash
|
39
|
-
# sudo dscl . -create /Users/someuser RealName "Lucius Q. User"
|
40
|
-
# sudo dscl . -create /Users/someuser UniqueID "1010" #use something not already in use
|
41
|
-
# sudo dscl . -create /Users/someuser PrimaryGroupID 80
|
42
|
-
# sudo dscl . -create /Users/someuser NFSHomeDirectory /Users/soemuser
|
43
|
-
#
|
44
|
-
# You can then use passwd to change the user's password, or use:
|
45
|
-
# sudo dscl . -passwd /Users/someuser password
|
46
|
-
|
47
|
-
# You'll also have to create the user's home directory and change ownership so the user can access it. And be sure that the UniqueID is, in fact, unique.
|
48
|
-
#
|
49
|
-
# This line will add the user to the administrator's group:
|
50
|
-
# sudo dscl . -append /Groups/admin GroupMembership someuser
|
51
|
-
def user_create
|
52
|
-
end
|
53
|
-
|
54
|
-
# add 1st user -- dscl . create /Groups/ladmins GroupMembership localadmin
|
55
|
-
# add more users -- dscl . append /Groups/ladmins GroupMembership 2ndlocaladmin
|
56
|
-
def user_add_to_group
|
57
|
-
end
|
58
|
-
|
59
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -delete /Groups/$VALUE GroupMembership $UID_USERNAME
|
60
|
-
def user_remove_from_group
|
61
|
-
end
|
62
|
-
|
63
|
-
# dscl . -delete /Users/yourUserName
|
64
|
-
# https://tutorialforlinux.com/2011/09/15/delete-users-and-groups-from-terminal/
|
65
|
-
def user_delete
|
66
|
-
end
|
67
|
-
|
68
|
-
# /usr/bin/dscl -plist -u diradmin -P #{adminpw} /LDAPv3/127.0.0.1/ -passwd /Users/#{uid} #{passwd}
|
69
|
-
def user_set_password
|
70
|
-
end
|
71
|
-
|
72
|
-
# /usr/bin/dscl /LDAPv3/127.0.0.1 auth #{uid} #{passwd}
|
73
|
-
def user_test_password
|
74
|
-
end
|
75
|
-
|
76
|
-
# /usr/bin/pwpolicy -a diradmin -p A-B1g-S3cret -u $UID_USERNAME -setpolicy "isDisabled=0"
|
77
|
-
def user_enable_login
|
78
|
-
end
|
79
|
-
|
80
|
-
# /usr/bin/pwpolicy -a diradmin -p A-B1g-S3cret -u $UID_USERNAME -setpolicy "isDisabled=1"
|
81
|
-
def user_disable_login
|
82
|
-
end
|
83
|
-
|
84
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME gidnumber "$VALUE"
|
85
|
-
def user_set_groupnumber
|
86
|
-
end
|
87
|
-
|
88
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME givenName "$VALUE"
|
89
|
-
def user_set_first_name
|
90
|
-
end
|
91
|
-
|
92
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME sn "$VALUE"
|
93
|
-
def user_set_last_name
|
94
|
-
end
|
95
|
-
|
96
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME apple-namesuffix "$VALUE"
|
97
|
-
def user_set_name_suffix
|
98
|
-
end
|
99
|
-
|
100
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME mail "$VALUE"
|
101
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME email "$VALUE"
|
102
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME apple-user-mailattribute "$VALUE"
|
103
|
-
def user_set_email
|
104
|
-
end
|
105
|
-
|
106
|
-
# create first keyword
|
107
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME apple-keyword "$VALUE"
|
108
|
-
# add a keyword
|
109
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$UID_USERNAME apple-keyword "$VALUE"
|
110
|
-
def user_set_keywords
|
111
|
-
end
|
112
|
-
|
113
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -append /Users/$UID_USERNAME apple-keyword "$VALUE"
|
114
|
-
def user_add_keywords
|
115
|
-
end
|
116
|
-
|
117
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME mobile "$VALUE"
|
118
|
-
def user_set_mobile_phone
|
119
|
-
end
|
120
|
-
|
121
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME telephoneNumber "$VALUE"
|
122
|
-
def user_set_work_phone
|
123
|
-
end
|
124
|
-
|
125
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME homePhone "$VALUE"
|
126
|
-
def user_set_home_phone
|
127
|
-
end
|
128
|
-
|
129
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME title "$VALUE"
|
130
|
-
def user_set_title
|
131
|
-
end
|
132
|
-
|
133
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME homedirectory "$VALUE"
|
134
|
-
def user_set_home_directoy
|
135
|
-
end
|
136
|
-
|
137
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME loginShell "$VALUE"
|
138
|
-
def user_set_shell
|
139
|
-
end
|
140
|
-
|
141
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME apple-company "$VALUE"
|
142
|
-
def user_set_company
|
143
|
-
end
|
144
|
-
alias_method :las_program_info, :user_set_company
|
145
|
-
|
146
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME street "$VALUE"
|
147
|
-
def user_set_street
|
148
|
-
end
|
149
|
-
alias_method :las_, :user_set_street
|
150
|
-
|
151
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID l "$VALUE"
|
152
|
-
def user_set_city
|
153
|
-
end
|
154
|
-
alias_method :las_, :user_set_city
|
155
|
-
|
156
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME st "$VALUE"
|
157
|
-
def user_set_state
|
158
|
-
end
|
159
|
-
alias_method :las_cultural_trip, :user_set_state
|
160
|
-
|
161
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME postalCode "$VALUE"
|
162
|
-
def user_set_postcode
|
163
|
-
end
|
164
|
-
alias_method :las_faculty_family, :user_set_postcode
|
165
|
-
|
166
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME apple-webloguri "$VALUE"
|
167
|
-
def user_set_blog
|
168
|
-
end
|
169
|
-
alias_method :las_, :user_set_blog
|
170
|
-
|
171
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME apple-organizationinfo "$VALUE"
|
172
|
-
def user_organizational_info
|
173
|
-
end
|
174
|
-
alias_method :las_link_student_to_parent, :user_organizational_info
|
175
|
-
|
176
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME apple-relationships "$VALUE"
|
177
|
-
def user_relationships
|
178
|
-
end
|
179
|
-
alias_method :las_link_parent_to_student, :user_relationships
|
180
|
-
|
181
|
-
# /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -create /Users/$UID_USERNAME labeledURI "$VALUE"
|
182
|
-
def user_set_homepage
|
183
|
-
end
|
184
|
-
alias_method :las_enrollment_date, :user_set_homepage
|
185
|
-
alias_method :las_start_date, :user_set_homepage
|
186
|
-
|
187
|
-
end
|
188
|
-
end
|