unix_ugm 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/command.rb +15 -0
- data/lib/unix_group.rb +47 -0
- data/lib/unix_user.rb +56 -0
- metadata +4 -1
data/lib/command.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class Command
|
2
|
+
#TODO: Move to own gem...
|
3
|
+
def self.execute(command)
|
4
|
+
pid = 0
|
5
|
+
exit_status = 0
|
6
|
+
|
7
|
+
# Open3.popen3([env,] cmd... [, opts])
|
8
|
+
Open3.popen3(command) do |stdin, stdout, stderr, wait_thr|
|
9
|
+
pid = wait_thr.pid # pid of the started process.
|
10
|
+
exit_status = wait_thr.value # Process::Status object returned.
|
11
|
+
end
|
12
|
+
|
13
|
+
exit_status
|
14
|
+
end
|
15
|
+
end
|
data/lib/unix_group.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require_relative 'command'
|
2
|
+
|
3
|
+
class UnixGroup
|
4
|
+
|
5
|
+
#------------------------------------------------------#
|
6
|
+
# Static methods
|
7
|
+
#------------------------------------------------------#
|
8
|
+
|
9
|
+
def self.list
|
10
|
+
passwd_file = File.open('/etc/group', 'r')
|
11
|
+
passwd_data = passwd_file.read
|
12
|
+
entries = passwd_data.split "\n"
|
13
|
+
list = []
|
14
|
+
entries.each do |entry|
|
15
|
+
fields = entry.split(':')
|
16
|
+
list << UnixGroup.new({
|
17
|
+
:name => fields[0],
|
18
|
+
:password => fields[1],
|
19
|
+
:gid => fields[2],
|
20
|
+
:users => fields[3]
|
21
|
+
})
|
22
|
+
end
|
23
|
+
list
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.find(name)
|
27
|
+
groups = list.select { |group| group.name == name }
|
28
|
+
groups.size != 0 ? groups.first : nil
|
29
|
+
end
|
30
|
+
|
31
|
+
#------------------------------------------------------#
|
32
|
+
# Instance methods
|
33
|
+
#------------------------------------------------------#
|
34
|
+
|
35
|
+
attr_reader :name,
|
36
|
+
:password,
|
37
|
+
:gid,
|
38
|
+
:users
|
39
|
+
|
40
|
+
def initialize(options)
|
41
|
+
@name = options[:name]
|
42
|
+
@password = options[:password]
|
43
|
+
@gid = options[:gid].to_i
|
44
|
+
@users = options[:users]
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
data/lib/unix_user.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require_relative 'command'
|
2
|
+
|
3
|
+
class UnixUser
|
4
|
+
|
5
|
+
#------------------------------------------------------#
|
6
|
+
# Static methods
|
7
|
+
#------------------------------------------------------#
|
8
|
+
|
9
|
+
def self.list
|
10
|
+
passwd_file = File.open('/etc/passwd', 'r')
|
11
|
+
passwd_data = passwd_file.read
|
12
|
+
entries = passwd_data.split "\n"
|
13
|
+
list = []
|
14
|
+
entries.each do |entry|
|
15
|
+
fields = entry.split(':')
|
16
|
+
list << UnixUser.new({
|
17
|
+
:username => fields[0],
|
18
|
+
:password => fields[1],
|
19
|
+
:uid => fields[2],
|
20
|
+
:gid => fields[3],
|
21
|
+
:user_info => fields[4],
|
22
|
+
:home_directory => fields[5],
|
23
|
+
:shell => fields[6]
|
24
|
+
})
|
25
|
+
end
|
26
|
+
list
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.find(username)
|
30
|
+
users = list.select { |user| user.username == username }
|
31
|
+
users.size != 0 ? users.first : nil
|
32
|
+
end
|
33
|
+
|
34
|
+
#------------------------------------------------------#
|
35
|
+
# Instance methods
|
36
|
+
#------------------------------------------------------#
|
37
|
+
|
38
|
+
attr_reader :username,
|
39
|
+
:password,
|
40
|
+
:uid,
|
41
|
+
:gid,
|
42
|
+
:user_info,
|
43
|
+
:home_directory,
|
44
|
+
:shell
|
45
|
+
|
46
|
+
def initialize(options)
|
47
|
+
@username = options[:username]
|
48
|
+
@password = options[:password]
|
49
|
+
@uid = options[:uid].to_i
|
50
|
+
@gid = options[:gid].to_i
|
51
|
+
@user_info = options[:user_info]
|
52
|
+
@home_directory = options[:home_directory]
|
53
|
+
@shell = options[:shell]
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: unix_ugm
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -18,6 +18,9 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- lib/unix_ugm.rb
|
21
|
+
- lib/unix_user.rb
|
22
|
+
- lib/unix_group.rb
|
23
|
+
- lib/command.rb
|
21
24
|
homepage: http://rubygems.org/gems/unix-ugm
|
22
25
|
licenses: []
|
23
26
|
post_install_message:
|