open_directory_utils 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +37 -0
- data/LICENSE.txt +21 -0
- data/README.md +111 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/open_directory_utils.rb +6 -0
- data/lib/open_directory_utils/clean_check.rb +30 -0
- data/lib/open_directory_utils/commands_group.rb +216 -0
- data/lib/open_directory_utils/commands_user.rb +680 -0
- data/lib/open_directory_utils/connection.rb +127 -0
- data/lib/open_directory_utils/dscl.rb +53 -0
- data/lib/open_directory_utils/pwpolicy.rb +48 -0
- data/lib/open_directory_utils/user_command_pattern.rb +188 -0
- data/lib/open_directory_utils/version.rb +5 -0
- data/open_directory_utils.gemspec +38 -0
- metadata +123 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 670f73215db5f440a0e47ace7c0efb2858491816ac0ce7a2de018d02c64f5f39
|
4
|
+
data.tar.gz: eff24211563c562e232ad371302dc7150221a5de41b37a0a943e7ed17701b0a4
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 180370d46964faa772fc81141ae279b5f64844da98e0da2d005b3dce4785b74b234f87c96cbde847a3c218737b2bb8cb0fcaa9ea1464c0eaad674851807ef5d3
|
7
|
+
data.tar.gz: 599b339abc2e70a0aa24e154ce7cfd08ce05bc567fdca051329f11c22ac5855ccbc165730cd6ca2d5de47d8ab6439bc8a8ea9cc82a251df1513a4ed9526e4940
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at btihen@gmail.com. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
open_directory_utils (0.1.0)
|
5
|
+
net-ssh (~> 4.2)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
diff-lcs (1.3)
|
11
|
+
net-ssh (4.2.0)
|
12
|
+
rake (12.3.1)
|
13
|
+
rspec (3.7.0)
|
14
|
+
rspec-core (~> 3.7.0)
|
15
|
+
rspec-expectations (~> 3.7.0)
|
16
|
+
rspec-mocks (~> 3.7.0)
|
17
|
+
rspec-core (3.7.1)
|
18
|
+
rspec-support (~> 3.7.0)
|
19
|
+
rspec-expectations (3.7.0)
|
20
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
21
|
+
rspec-support (~> 3.7.0)
|
22
|
+
rspec-mocks (3.7.0)
|
23
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
24
|
+
rspec-support (~> 3.7.0)
|
25
|
+
rspec-support (3.7.1)
|
26
|
+
|
27
|
+
PLATFORMS
|
28
|
+
ruby
|
29
|
+
|
30
|
+
DEPENDENCIES
|
31
|
+
bundler (~> 1.16)
|
32
|
+
open_directory_utils!
|
33
|
+
rake (~> 12.3)
|
34
|
+
rspec (~> 3.7)
|
35
|
+
|
36
|
+
BUNDLED WITH
|
37
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Bill Tihen
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,111 @@
|
|
1
|
+
# OpenDirectoryUtils
|
2
|
+
|
3
|
+
This Gem allows one to build or send pre-built commands to control
|
4
|
+
(common OD and LDAP attributes) on an OpenDirectory server.
|
5
|
+
|
6
|
+
One can also build custom DSCL commands and send them to the server as needed too.
|
7
|
+
|
8
|
+
## Change Log
|
9
|
+
|
10
|
+
* **v0.1.0** - 2018-06-06
|
11
|
+
- can adjust and delete OD attributes for users and groups (pre-built ldap attributes comming soon)
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Add this line to your application's Gemfile:
|
16
|
+
|
17
|
+
```ruby
|
18
|
+
gem 'open_directory_utils'
|
19
|
+
```
|
20
|
+
|
21
|
+
And then execute:
|
22
|
+
|
23
|
+
$ bundle
|
24
|
+
|
25
|
+
Or install it yourself as:
|
26
|
+
|
27
|
+
$ gem install open_directory_utils
|
28
|
+
|
29
|
+
## Usage
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
require 'open_directory_utils'
|
33
|
+
|
34
|
+
# Usually Instantiate using ENV-VARS -
|
35
|
+
# srv_host_name: ENV['OD_HOSTNAME'],
|
36
|
+
# srv_user_name: ENV['OD_USERNAME'],
|
37
|
+
# dir_user_name: ENV['DIR_ADMIN_USER'],
|
38
|
+
# dir_password: ENV['DIR_ADMIN_PASS'],
|
39
|
+
|
40
|
+
# Instantiating using params
|
41
|
+
od = OpenDirectoryUtils.new(
|
42
|
+
{ srv_host_name: 'od_hostname', srv_user_name: 'od_ssh_username',
|
43
|
+
dir_user_name: 'directory_admin_username',
|
44
|
+
dir_password: 'directory_admin_password'
|
45
|
+
}
|
46
|
+
)
|
47
|
+
|
48
|
+
user_params = { user_name: 'someone', user_number: 9876, group_number: 4321,
|
49
|
+
first_name: 'Someone', last__name: 'Special',
|
50
|
+
}
|
51
|
+
group_params = {group_name: 'agroup', long_name: 'A Group', group_number: 5432}
|
52
|
+
|
53
|
+
# create a user
|
54
|
+
od.run( command: :user_create_full, params: user_params )
|
55
|
+
|
56
|
+
# update user's record (all dscl and ldap fields are available)
|
57
|
+
od.run( command: :user_set_first_email,
|
58
|
+
params: {user_name: 'someone', email: 'someone@example.com'} )
|
59
|
+
# add a second email address
|
60
|
+
od.run( command: :user_append_email,
|
61
|
+
params: {user_name: 'someone', email: 'second@example.com'} )
|
62
|
+
# fix spelling of first name
|
63
|
+
od.run( command: :user_set_first_name,
|
64
|
+
params: {user_name: 'someone', first_name: 'John'} )
|
65
|
+
|
66
|
+
# get user's record
|
67
|
+
od.run( command: :user_info, params: user_params )
|
68
|
+
|
69
|
+
# create a group
|
70
|
+
od.run( command: :group_create_full, params: group_params )
|
71
|
+
|
72
|
+
# add the first user to the group
|
73
|
+
od.run( command: :group_add_first_user,
|
74
|
+
params: {user_name: 'someone', group_name: 'agroup'} )
|
75
|
+
# add additional user to the group
|
76
|
+
od.run( command: :user_append_to_group,
|
77
|
+
params: {user_name: 'existinguser', group_name: 'agroup'} )
|
78
|
+
|
79
|
+
# get group record and members inf
|
80
|
+
od.run( command: :group_info, params: user_params )
|
81
|
+
|
82
|
+
# remove a user from a group
|
83
|
+
od.run( command: :user_remove_from_group,
|
84
|
+
params: {user_name: 'someone', group_name: 'agroup'})
|
85
|
+
od.run( command: :user_remove_from_group,
|
86
|
+
params: {user_name: 'existinguser', group_name: 'agroup'})
|
87
|
+
|
88
|
+
# delete a group
|
89
|
+
od.run( command: :group_delete, params: {group__name: 'agroup'})
|
90
|
+
|
91
|
+
# delete a user
|
92
|
+
|
93
|
+
```
|
94
|
+
|
95
|
+
## Development
|
96
|
+
|
97
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
98
|
+
|
99
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
100
|
+
|
101
|
+
## Contributing
|
102
|
+
|
103
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/open_directory_utils. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
104
|
+
|
105
|
+
## License
|
106
|
+
|
107
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
108
|
+
|
109
|
+
## Code of Conduct
|
110
|
+
|
111
|
+
Everyone interacting in the OpenDirectoryUtils project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/open_directory_utils/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "open_directory_utils"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module OpenDirectoryUtils
|
2
|
+
|
3
|
+
# https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/dscl.1.html
|
4
|
+
# 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
|
5
|
+
module CleanCheck
|
6
|
+
|
7
|
+
def assert(&block)
|
8
|
+
raise ArgumentError unless block.call
|
9
|
+
end
|
10
|
+
|
11
|
+
def check_critical_attribute(attrib, key, value=nil)
|
12
|
+
assert{not attrib[key].nil?}
|
13
|
+
attrib[key] = attrib[key].to_s.strip
|
14
|
+
assert{not attrib[key].eql? ''}
|
15
|
+
assert{not attrib[key].include? ' '} if key.eql? :scope
|
16
|
+
assert{not attrib[key].include? ' '} if [:uid, :username, :record_name].include? key
|
17
|
+
rescue NoMethodError, ArgumentError => error
|
18
|
+
message = "#{key}: '#{attrib[key].inspect}' invalid"
|
19
|
+
message += ", value_name: :#{value}" unless value.nil?
|
20
|
+
raise ArgumentError, message
|
21
|
+
end
|
22
|
+
|
23
|
+
def tidy_attribs(attribs)
|
24
|
+
user_attrs = {}
|
25
|
+
attribs.each{ |k,v| user_attrs[k] = v.to_s.strip }
|
26
|
+
return user_attrs
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,216 @@
|
|
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 groups to accomplish common actions
|
7
|
+
# @note - these commands were derived from the following resrouces:
|
8
|
+
# * http://krypted.com/mac-os-x/create-groups-using-dscl/
|
9
|
+
# * https://apple.stackexchange.com/questions/307173/creating-a-group-via-users-groups-in-command-line?utm_medium=organic&utm_source=google_rich_qa&utm_campaign=google_rich_qa
|
10
|
+
module CommandsGroup
|
11
|
+
|
12
|
+
include OpenDirectoryUtils::Dscl
|
13
|
+
include OpenDirectoryUtils::CleanCheck
|
14
|
+
|
15
|
+
def group_record_name_alternatives(attribs)
|
16
|
+
attribs[:record_name] = nil
|
17
|
+
attribs[:record_name] = attribs[:group_name]
|
18
|
+
attribs[:record_name] = attribs[:record_name] || attribs[:groupname]
|
19
|
+
attribs[:record_name] = attribs[:record_name] || attribs[:gid]
|
20
|
+
attribs[:record_name] = attribs[:record_name] || attribs[:cn]
|
21
|
+
return attribs
|
22
|
+
end
|
23
|
+
|
24
|
+
# dscl . read /Groups/ladmins
|
25
|
+
def group_get_info(attribs, dir_info)
|
26
|
+
attribs = group_record_name_alternatives(attribs)
|
27
|
+
|
28
|
+
check_critical_attribute( attribs, :record_name )
|
29
|
+
|
30
|
+
command = {action: 'read', scope: 'Groups', value: nil}
|
31
|
+
user_attrs = attribs.merge(command)
|
32
|
+
|
33
|
+
dscl( user_attrs, dir_info )
|
34
|
+
end
|
35
|
+
alias_method :group_info, :group_get_info
|
36
|
+
|
37
|
+
def group_exists?(attribs, dir_info)
|
38
|
+
group_get_info(attribs, dir_info)
|
39
|
+
end
|
40
|
+
|
41
|
+
# add 1st user -- dscl . create /Groups/ladmins GroupMembership localadmin
|
42
|
+
# add more users -- dscl . append /Groups/ladmins GroupMembership 2ndlocaladmin
|
43
|
+
def group_add_first_user(attribs, dir_info)
|
44
|
+
attribs = group_record_name_alternatives(attribs)
|
45
|
+
|
46
|
+
# value = username
|
47
|
+
attribs[:value] = attribs[:value] || attribs[:user_name]
|
48
|
+
attribs[:value] = attribs[:value] || attribs[:username]
|
49
|
+
attribs[:value] = attribs[:value] || attribs[:uid]
|
50
|
+
|
51
|
+
check_critical_attribute( attribs, :record_name )
|
52
|
+
check_critical_attribute( attribs, :value, :username )
|
53
|
+
|
54
|
+
# Will assume we are not adding the first user!
|
55
|
+
command = { action: 'create', scope: 'Groups',
|
56
|
+
attribute: 'GroupMembership'}
|
57
|
+
user_attrs = attribs.merge(command)
|
58
|
+
|
59
|
+
dscl( user_attrs, dir_info )
|
60
|
+
end
|
61
|
+
|
62
|
+
def group_has_user?(attribs, dir_info)
|
63
|
+
group_get_info(attribs, dir_info)
|
64
|
+
end
|
65
|
+
|
66
|
+
# add 1st user -- dscl . create /Groups/ladmins GroupMembership localadmin
|
67
|
+
# add more users -- dscl . append /Groups/ladmins GroupMembership 2ndlocaladmin
|
68
|
+
def group_add_user(attribs, dir_info)
|
69
|
+
attribs = group_record_name_alternatives(attribs)
|
70
|
+
|
71
|
+
# value = username
|
72
|
+
attribs[:value] = attribs[:value] || attribs[:user_name]
|
73
|
+
attribs[:value] = attribs[:value] || attribs[:username]
|
74
|
+
attribs[:value] = attribs[:value] || attribs[:uid]
|
75
|
+
|
76
|
+
check_critical_attribute( attribs, :record_name )
|
77
|
+
check_critical_attribute( attribs, :value, :username )
|
78
|
+
|
79
|
+
# Will assume we are not adding the first user!
|
80
|
+
command = { action: 'append', scope: 'Groups',
|
81
|
+
attribute: 'GroupMembership'}
|
82
|
+
user_attrs = attribs.merge(command)
|
83
|
+
|
84
|
+
dscl( user_attrs, dir_info )
|
85
|
+
end
|
86
|
+
|
87
|
+
# # /usr/bin/dscl -u diradmin -P A-B1g-S3cret /LDAPv3/127.0.0.1/ -delete /Groups/$SHORTNAME GroupMembership $VALUE
|
88
|
+
# # dseditgroup -o edit -d $Username -t user $GroupName
|
89
|
+
def group_remove_user(attribs, dir_info)
|
90
|
+
attribs = group_record_name_alternatives(attribs)
|
91
|
+
|
92
|
+
# value <- is username
|
93
|
+
attribs[:value] = attribs[:value] || attribs[:user_name]
|
94
|
+
attribs[:value] = attribs[:value] || attribs[:username]
|
95
|
+
attribs[:value] = attribs[:value] || attribs[:uid]
|
96
|
+
|
97
|
+
check_critical_attribute( attribs, :record_name )
|
98
|
+
check_critical_attribute( attribs, :value, :username )
|
99
|
+
|
100
|
+
command = { action: 'delete', scope: 'Groups',
|
101
|
+
attribute: 'GroupMembership'}
|
102
|
+
user_attrs = attribs.merge(command)
|
103
|
+
|
104
|
+
dscl( user_attrs, dir_info )
|
105
|
+
end
|
106
|
+
|
107
|
+
# dscl . -delete /Groups/yourGroupName
|
108
|
+
# https://tutorialforlinux.com/2011/09/15/delete-users-and-groups-from-terminal/
|
109
|
+
def group_delete(attribs, dir_info)
|
110
|
+
attribs = group_record_name_alternatives(attribs)
|
111
|
+
|
112
|
+
check_critical_attribute( attribs, :record_name )
|
113
|
+
|
114
|
+
command = {action: 'delete', scope: 'Groups', attribute: nil, value: nil}
|
115
|
+
user_attrs = attribs.merge(command)
|
116
|
+
|
117
|
+
dscl( user_attrs, dir_info )
|
118
|
+
end
|
119
|
+
|
120
|
+
def group_create_min(attribs, dir_info)
|
121
|
+
attribs = group_record_name_alternatives(attribs)
|
122
|
+
|
123
|
+
check_critical_attribute( attribs, :record_name )
|
124
|
+
|
125
|
+
command = {action: 'create', scope: 'Groups', attribute: nil, value: nil}
|
126
|
+
user_attrs = attribs.merge(command)
|
127
|
+
|
128
|
+
dscl( user_attrs, dir_info )
|
129
|
+
end
|
130
|
+
|
131
|
+
def group_set_primary_group_id(attribs, dir_info)
|
132
|
+
attribs = group_record_name_alternatives(attribs)
|
133
|
+
|
134
|
+
attribs[:value] = attribs[:value] || attribs[:primary_group_id]
|
135
|
+
attribs[:value] = attribs[:value] || attribs[:group_number]
|
136
|
+
attribs[:value] = attribs[:value] || attribs[:groupnumber]
|
137
|
+
attribs[:value] = attribs[:value] || attribs[:gidnumber]
|
138
|
+
attribs[:value] = attribs[:value] || attribs[:group_id]
|
139
|
+
|
140
|
+
check_critical_attribute( attribs, :record_name )
|
141
|
+
check_critical_attribute( attribs, :value, :group_id )
|
142
|
+
|
143
|
+
command = {action: 'create', scope: 'Groups', attribute: 'PrimaryGroupID'}
|
144
|
+
user_attrs = attribs.merge(command)
|
145
|
+
|
146
|
+
dscl( user_attrs, dir_info )
|
147
|
+
end
|
148
|
+
|
149
|
+
def group_set_real_name(attribs, dir_info)
|
150
|
+
attribs = group_record_name_alternatives(attribs)
|
151
|
+
|
152
|
+
attribs[:value] = attribs[:value] || attribs[:real_name]
|
153
|
+
attribs[:value] = attribs[:value] || attribs[:long_name]
|
154
|
+
attribs[:value] = attribs[:value] || attribs[:longname]
|
155
|
+
attribs[:value] = attribs[:value] || attribs[:full_name]
|
156
|
+
attribs[:value] = attribs[:value] || attribs[:fullname]
|
157
|
+
attribs[:value] = attribs[:value] || attribs[:name]
|
158
|
+
attribs[:value] = attribs[:value] || attribs[:group_name]
|
159
|
+
attribs[:value] = attribs[:value] || attribs[:groupname]
|
160
|
+
attribs[:value] = attribs[:value] || attribs[:gid]
|
161
|
+
attribs[:value] = attribs[:value] || attribs[:cn]
|
162
|
+
|
163
|
+
check_critical_attribute( attribs, :record_name )
|
164
|
+
check_critical_attribute( attribs, :value, :real_name )
|
165
|
+
|
166
|
+
command = {action: 'create', scope: 'Groups', attribute: 'RealName'}
|
167
|
+
user_attrs = attribs.merge(command)
|
168
|
+
|
169
|
+
dscl( user_attrs, dir_info )
|
170
|
+
end
|
171
|
+
|
172
|
+
# probably can't create password for group?
|
173
|
+
# /usr/bin/dscl -u diradmin -P liaP-meD-Aj-pHi-hOb-en-c /LDAPv3/127.0.0.1/ -create /Groups/odgrouptest passwd "*"
|
174
|
+
# "<main> attribute status: eDSNoStdMappingAvailable\n" +
|
175
|
+
# "<dscl_cmd> DS Error: -14140 (eDSNoStdMappingAvailable)"]
|
176
|
+
def group_set_passwd(attribs, dir_info)
|
177
|
+
attribs = group_record_name_alternatives(attribs)
|
178
|
+
|
179
|
+
attribs[:value] = attribs[:value] || attribs[:password]
|
180
|
+
attribs[:value] = attribs[:value] || attribs[:passwd]
|
181
|
+
attribs[:value] = attribs[:value] || '*'
|
182
|
+
|
183
|
+
check_critical_attribute( attribs, :record_name )
|
184
|
+
check_critical_attribute( attribs, :value, :password )
|
185
|
+
|
186
|
+
command = {action: 'passwd', scope: 'Groups', attribute: nil}
|
187
|
+
user_attrs = attribs.merge(command)
|
188
|
+
|
189
|
+
dscl( user_attrs, dir_info )
|
190
|
+
end
|
191
|
+
alias_method :group_set_password, :group_set_passwd
|
192
|
+
|
193
|
+
# create group -- dscl . -create /Groups/ladmins
|
194
|
+
# add group passwd -- dscl . -create /Groups/ladmins passwd “*”
|
195
|
+
# add group name -- dscl . -create /Groups/ladmins RealName “Local Admins”
|
196
|
+
# group ID number -- dscl . -create /Groups/ladmins gid 400
|
197
|
+
# group id number -- dscl . -create /Groups/GROUP PrimaryGroupID GID
|
198
|
+
def group_create_full(attribs, dir_info)
|
199
|
+
attribs = group_record_name_alternatives(attribs)
|
200
|
+
|
201
|
+
answer = []
|
202
|
+
attribs[:value] = nil
|
203
|
+
answer << group_create_min( attribs, dir_info )
|
204
|
+
attribs[:value] = nil
|
205
|
+
answer << group_set_primary_group_id( attribs, dir_info )
|
206
|
+
attribs[:value] = nil
|
207
|
+
answer << group_set_real_name( attribs, dir_info )
|
208
|
+
# attribs[:value] = nil
|
209
|
+
# answer << group_set_password( attribs, dir_info )
|
210
|
+
|
211
|
+
return answer
|
212
|
+
end
|
213
|
+
alias_method :group_create, :group_create_full
|
214
|
+
|
215
|
+
end
|
216
|
+
end
|