sys-admin 1.5.2 → 1.5.3
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +7 -0
- data/README +96 -101
- data/Rakefile +55 -42
- data/ext/sys/admin.h +21 -21
- data/sys-admin.gemspec +28 -0
- data/test/test_sys_admin.rb +5 -5
- data/test/test_sys_admin_unix.rb +233 -234
- metadata +38 -18
data/CHANGES
CHANGED
@@ -1,3 +1,10 @@
|
|
1
|
+
== 1.5.3 - 6-Oct-2010
|
2
|
+
* Refactored the Rakefile. The old installation tasks have been replaced
|
3
|
+
with gem build and install tasks. In addition, the platform handling has
|
4
|
+
been updated for MS Windows.
|
5
|
+
* Portions of the gemspec have been moved into the Rakefile gem tasks.
|
6
|
+
* Deploying the mingw gem by default for MS Windows now.
|
7
|
+
|
1
8
|
== 1.5.2 - 2-Aug-2009
|
2
9
|
* Now compatible with Ruby 1.9.x.
|
3
10
|
* Added test-unit as a development dependency.
|
data/README
CHANGED
@@ -1,161 +1,156 @@
|
|
1
1
|
== Description
|
2
|
-
|
3
|
-
Etc module.
|
2
|
+
The sys-admin library is a unified, cross platform replacement for the Etc module.
|
4
3
|
|
5
4
|
== Installation
|
6
|
-
|
7
|
-
gem install sys-admin
|
8
|
-
= Local installation
|
9
|
-
rake test (optional)
|
10
|
-
rake install
|
5
|
+
gem install sys-admin
|
11
6
|
|
12
7
|
== Synopsis
|
13
|
-
|
14
|
-
|
8
|
+
require 'sys/admin'
|
9
|
+
include Sys
|
15
10
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
11
|
+
# Yields a User object for each user
|
12
|
+
Admin.users{ |user|
|
13
|
+
p user
|
14
|
+
}
|
20
15
|
|
21
|
-
|
22
|
-
|
16
|
+
# Returns an Array of User objects
|
17
|
+
a = Admin.users
|
23
18
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
# Yields a Group object for each group
|
20
|
+
Admin.groups{ |group|
|
21
|
+
p group
|
22
|
+
}
|
28
23
|
|
29
|
-
|
30
|
-
|
24
|
+
# Returns an Array of Group objects
|
25
|
+
g = Admin.groups
|
31
26
|
|
32
|
-
|
33
|
-
|
27
|
+
# Get information about a particular user
|
28
|
+
p Admin.get_user("nobody")
|
34
29
|
|
35
|
-
|
36
|
-
|
30
|
+
# Get information about a particular group
|
31
|
+
p Admin.get_group("adm")
|
37
32
|
|
38
33
|
== Admin
|
39
34
|
Admin.get_login
|
40
|
-
|
35
|
+
Returns the user name (only) of the current login.
|
41
36
|
|
42
37
|
Admin.get_user(name, options = {})
|
43
38
|
Admin.get_user(uid, options = {})
|
44
|
-
|
45
|
-
|
46
|
-
|
39
|
+
Returns a User object based on +name+ or +uid+. The +options+ hash is
|
40
|
+
for MS Windows only, and allows you to restrict the search based on the
|
41
|
+
options you provide, e.g. 'domain' or 'localaccount'.
|
47
42
|
|
48
43
|
Admin.get_group(name, options = {})
|
49
44
|
Admin.get_group(gid, options = {})
|
50
|
-
|
51
|
-
|
52
|
-
|
45
|
+
Returns a Group object based on +name+ or +uid+. The +options+ hash is
|
46
|
+
for MS Windows only, and allows you to restrict the search based on the
|
47
|
+
options you provide, e.g. 'domain' or 'localaccount'.
|
53
48
|
|
54
49
|
Admin.groups(options = {})
|
55
50
|
Admin.groups(options = {}){ |group| ... }
|
56
|
-
|
57
|
-
|
51
|
+
In block form, yields a Group object for each user on the system. In
|
52
|
+
non-block form, returns an Array of Group objects.
|
58
53
|
|
59
|
-
|
60
|
-
|
54
|
+
The +options+ hash is for MS Windows only, and allows you to restrict the
|
55
|
+
search based on the options you provide, e.g. 'domain' or 'localaccount'.
|
61
56
|
|
62
57
|
Admin.users(options = {})
|
63
58
|
Admin.users(options = {}){ |user| ... }
|
64
|
-
|
65
|
-
|
59
|
+
In block form, yields a User object for each user on the system. In
|
60
|
+
non-block form, returns an Array of User objects.
|
66
61
|
|
67
|
-
|
68
|
-
|
62
|
+
The +options+ hash is for MS Windows only, and allows you to restrict the
|
63
|
+
search based on the options you provide, e.g. 'domain' or 'localaccount'.
|
69
64
|
|
70
65
|
== User class
|
71
66
|
=== User (Windows)
|
72
|
-
|
67
|
+
The User class has the following attributes on MS Windows systems:
|
73
68
|
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
69
|
+
* account_type
|
70
|
+
* caption
|
71
|
+
* description
|
72
|
+
* domain
|
73
|
+
* password
|
74
|
+
* full_name
|
75
|
+
* install_date
|
76
|
+
* name
|
77
|
+
* sid
|
78
|
+
* status
|
79
|
+
* disabled?
|
80
|
+
* local?
|
81
|
+
* lockout?
|
82
|
+
* password_changeable?
|
83
|
+
* password_expires?
|
84
|
+
* password_required?
|
90
85
|
|
91
86
|
=== User (Unix)
|
92
|
-
|
87
|
+
The User class has the following attributes on Unix systems:
|
93
88
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
89
|
+
* name
|
90
|
+
* passwd
|
91
|
+
* uid
|
92
|
+
* gid
|
93
|
+
* dir
|
94
|
+
* shell
|
95
|
+
* gecos
|
96
|
+
* quota
|
97
|
+
* age
|
98
|
+
* class
|
99
|
+
* comment
|
100
|
+
* change
|
101
|
+
* expire
|
107
102
|
|
108
103
|
== Group Classes
|
109
104
|
=== Group (Windows)
|
110
|
-
|
105
|
+
The Group class has the following attributes on MS Windows systems:
|
111
106
|
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
107
|
+
* caption
|
108
|
+
* description
|
109
|
+
* domain
|
110
|
+
* install_date
|
111
|
+
* name
|
112
|
+
* sid
|
113
|
+
* status
|
114
|
+
* gid
|
115
|
+
* local?
|
121
116
|
|
122
117
|
=== Group (Unix)
|
123
|
-
|
118
|
+
The Group class has the following attributes on Unix systems:
|
124
119
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
120
|
+
* name
|
121
|
+
* gid
|
122
|
+
* members
|
123
|
+
* passwd
|
129
124
|
|
130
125
|
== Error Classes
|
131
126
|
Admin::Error < StandardError
|
132
|
-
|
127
|
+
Raised if anything goes wrong with any of the above methods.
|
133
128
|
|
134
129
|
== Developer's Notes
|
135
130
|
=== MS Windows
|
136
|
-
|
137
|
-
|
138
|
-
|
131
|
+
The Windows version now uses a win32ole + WMI approach to getting
|
132
|
+
information. This means that the WMI service must be running on the
|
133
|
+
target machine in order to work (which it is, by default).
|
139
134
|
|
140
135
|
=== UNIX
|
141
|
-
|
142
|
-
|
143
|
-
|
136
|
+
The underlying implementation is similar to core Ruby's Etc implementation.
|
137
|
+
But, in addition to the different interface, I use the re-entrant version
|
138
|
+
of the appropriate functions when available.
|
144
139
|
|
145
140
|
== Future Plans
|
146
|
-
|
147
|
-
|
141
|
+
Make the User and Group objects comparable.
|
142
|
+
Add ability to add, configure and delete users on Unix platforms.
|
148
143
|
|
149
144
|
== Known Bugs
|
150
|
-
|
151
|
-
|
145
|
+
None that I'm aware of. If you find any, please log them on the project
|
146
|
+
page at http://www.rubyforge.org/projects/sysutils.
|
152
147
|
|
153
148
|
== License
|
154
|
-
|
149
|
+
Artistic 2.0
|
155
150
|
|
156
151
|
== Copyright
|
157
|
-
|
158
|
-
|
152
|
+
(C) 2005-2010, Daniel J. Berger
|
153
|
+
All Rights Reserved
|
159
154
|
|
160
155
|
== Author
|
161
|
-
|
156
|
+
Daniel J. Berger
|
data/Rakefile
CHANGED
@@ -2,60 +2,73 @@ require 'rake'
|
|
2
2
|
require 'rake/clean'
|
3
3
|
require 'rake/testtask'
|
4
4
|
require 'rbconfig'
|
5
|
-
|
5
|
+
|
6
|
+
WINDOWS = Config::CONFIG['host_os'] =~ /msdos|mswin|win32|mingw|cygwin/i
|
6
7
|
|
7
8
|
desc "Clean the build files for the sys-admin source for UNIX systems"
|
8
9
|
task :clean do
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
Dir['*.gem'].each{ |f| File.delete(f) } # Remove any .gem files
|
11
|
+
unless WINDOWS
|
12
|
+
Dir.chdir('ext') do
|
13
|
+
build_file = 'admin.' + Config::CONFIG['DLEXT']
|
14
|
+
sh 'make distclean' if File.exists?(build_file)
|
15
|
+
File.delete("sys/#{build_file}") if File.exists?("sys/#{build_file}")
|
16
|
+
end
|
17
|
+
end
|
16
18
|
end
|
17
19
|
|
18
|
-
desc "Build the sys-admin
|
20
|
+
desc "Build the sys-admin library on UNIX systems (but don't install it)"
|
19
21
|
task :build => [:clean] do
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
22
|
+
unless WINDOWS
|
23
|
+
Dir.chdir('ext') do
|
24
|
+
ruby 'extconf.rb'
|
25
|
+
sh 'make'
|
26
|
+
build_file = 'admin.' + Config::CONFIG['DLEXT']
|
27
|
+
FileUtils.cp(build_file, 'sys')
|
28
|
+
end
|
29
|
+
end
|
28
30
|
end
|
29
31
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
32
|
+
namespace :gem do
|
33
|
+
desc "Create a sys-admin gem file."
|
34
|
+
task :create => [:clean] do
|
35
|
+
spec = eval(IO.read('sys-admin.gemspec'))
|
36
|
+
|
37
|
+
if WINDOWS
|
38
|
+
spec.platform = Gem::Platform::CURRENT
|
39
|
+
spec.files = spec.files.reject{ |f| f.include?('ext') }
|
40
|
+
spec.add_dependency('win32-security', '>= 0.1.2')
|
41
|
+
else
|
42
|
+
spec.files = spec.files.reject{ |f| f.include?('lib') }
|
43
|
+
spec.extensions = ['ext/extconf.rb']
|
44
|
+
spec.extra_rdoc_files << 'ext/sys/admin.c'
|
45
|
+
end
|
46
|
+
|
47
|
+
Gem::Builder.new(spec).build
|
48
|
+
end
|
49
|
+
|
50
|
+
desc "Install the sys-admin gem."
|
51
|
+
task :install => [:create] do
|
52
|
+
gem = Dir['*.gem'].first
|
53
|
+
sh "gem install #{gem}"
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
desc "Run the test suite"
|
47
|
-
Rake::TestTask.new(
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
58
|
+
Rake::TestTask.new('test') do |t|
|
59
|
+
if WINDOWS
|
60
|
+
t.libs << 'lib'
|
61
|
+
else
|
62
|
+
task :test => :build
|
63
|
+
t.libs << 'ext'
|
64
|
+
t.libs.delete('lib')
|
65
|
+
end
|
66
|
+
t.libs << 'test'
|
67
|
+
t.test_files = FileList['test/test_sys_admin.rb']
|
57
68
|
end
|
58
69
|
|
59
70
|
task :test do
|
60
|
-
|
71
|
+
Rake.application[:clean].execute
|
61
72
|
end
|
73
|
+
|
74
|
+
task :default => :test
|
data/ext/sys/admin.h
CHANGED
@@ -8,7 +8,7 @@
|
|
8
8
|
#include <errno.h>
|
9
9
|
#include <string.h>
|
10
10
|
|
11
|
-
#define SYS_ADMIN_VERSION "1.5.
|
11
|
+
#define SYS_ADMIN_VERSION "1.5.3"
|
12
12
|
|
13
13
|
#if defined(__MACH__) || defined(__APPLE__)
|
14
14
|
#define __BSD__
|
@@ -69,32 +69,32 @@ VALUE cUser, cGroup, cAdminError;
|
|
69
69
|
* Helper function that returns a User object based on user ID.
|
70
70
|
*/
|
71
71
|
static VALUE get_user_by_num(VALUE v_uid){
|
72
|
-
|
73
|
-
|
72
|
+
volatile VALUE v_user;
|
73
|
+
uid_t uid = NUM2INT(v_uid);
|
74
74
|
|
75
75
|
#ifdef HAVE_GETPWUID_R
|
76
|
-
|
77
|
-
|
78
|
-
|
76
|
+
char buf[USER_BUF_SIZE];
|
77
|
+
struct passwd pwd;
|
78
|
+
struct passwd* pwdbuf;
|
79
79
|
|
80
|
-
|
81
|
-
|
80
|
+
if(getpwuid_r(uid, &pwd, buf, sizeof(buf), &pwdbuf) != 0)
|
81
|
+
rb_raise(cAdminError, "%s", strerror(errno));
|
82
82
|
|
83
|
-
|
84
|
-
|
83
|
+
if(!pwdbuf)
|
84
|
+
rb_raise(cAdminError, "no user found for %i:", uid);
|
85
85
|
|
86
|
-
|
86
|
+
v_user = get_user(pwdbuf);
|
87
87
|
#elif HAVE_GETPWUID
|
88
|
-
|
89
|
-
|
90
|
-
|
88
|
+
struct passwd* pwd;
|
89
|
+
if( (pwd = getpwuid(uid)) == NULL)
|
90
|
+
rb_raise(cAdminError, "no user found for: %i", uid);
|
91
91
|
|
92
|
-
|
92
|
+
v_user = get_user(pwd);
|
93
93
|
#else
|
94
|
-
|
94
|
+
rb_raise(rb_eNotImpError, "getting user by user ID not supported");
|
95
95
|
#endif
|
96
96
|
|
97
|
-
|
97
|
+
return v_user;
|
98
98
|
}
|
99
99
|
|
100
100
|
/*
|
@@ -459,8 +459,8 @@ int get_lastlog_info(struct passwd* pwd, VALUE v_user){
|
|
459
459
|
* that endpwent() is called in the block form of Admin.groups.
|
460
460
|
*/
|
461
461
|
static VALUE admin_groups_cleanup(){
|
462
|
-
|
463
|
-
|
462
|
+
endgrent();
|
463
|
+
return Qnil;
|
464
464
|
}
|
465
465
|
|
466
466
|
/*
|
@@ -470,6 +470,6 @@ static VALUE admin_groups_cleanup(){
|
|
470
470
|
* that endpwent() is called in the block form of Admin.users.
|
471
471
|
*/
|
472
472
|
static VALUE admin_users_cleanup(){
|
473
|
-
|
474
|
-
|
473
|
+
endpwent();
|
474
|
+
return Qnil;
|
475
475
|
}
|
data/sys-admin.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
# Do not use this file directly. Build the gem via the Rake tasks.
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'sys-admin'
|
7
|
+
spec.version = '1.5.3'
|
8
|
+
spec.author = 'Daniel J. Berger'
|
9
|
+
spec.license = 'Artistic 2.0'
|
10
|
+
spec.email = 'djberg96@gmail.com'
|
11
|
+
spec.homepage = 'http://www.github.com/djberg96/sysutils'
|
12
|
+
spec.summary = 'A unified, cross platform replacement for the "etc" library.'
|
13
|
+
spec.test_file = 'test/test_sys_admin.rb'
|
14
|
+
spec.files = Dir['**/*'].reject{ |f| f.include?('git') }
|
15
|
+
|
16
|
+
spec.extra_rdoc_files = ['CHANGES', 'README', 'MANIFEST']
|
17
|
+
spec.rubyforge_project = 'sysutils'
|
18
|
+
|
19
|
+
spec.add_development_dependency('test-unit', '>= 2.1.1')
|
20
|
+
|
21
|
+
spec.description = <<-EOF
|
22
|
+
The sys-admin library is a unified, cross platform replacement for the
|
23
|
+
'etc' library that ships as part of the Ruby standard library. It
|
24
|
+
provides a common interface for all platforms, including MS Windows. In
|
25
|
+
addition, it provides an interface for adding, deleting and configuring
|
26
|
+
users on MS Windows.
|
27
|
+
EOF
|
28
|
+
end
|
data/test/test_sys_admin.rb
CHANGED
@@ -9,13 +9,13 @@ gem 'test-unit'
|
|
9
9
|
require 'test/unit'
|
10
10
|
|
11
11
|
if File::ALT_SEPARATOR
|
12
|
-
|
12
|
+
require 'test_sys_admin_windows'
|
13
13
|
else
|
14
|
-
|
14
|
+
require 'test_sys_admin_unix'
|
15
15
|
end
|
16
16
|
|
17
17
|
class TC_Sys_Admin_All < Test::Unit::TestCase
|
18
|
-
|
19
|
-
|
20
|
-
|
18
|
+
def test_version
|
19
|
+
assert_equal('1.5.3', Sys::Admin::VERSION)
|
20
|
+
end
|
21
21
|
end
|
data/test/test_sys_admin_unix.rb
CHANGED
@@ -9,238 +9,237 @@ require 'sys/admin'
|
|
9
9
|
include Sys
|
10
10
|
|
11
11
|
class TC_Sys_Admin_Unix < Test::Unit::TestCase
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
end
|
12
|
+
def setup
|
13
|
+
@user = 'nobody'
|
14
|
+
@user_id = 0
|
15
|
+
@group = 'sys'
|
16
|
+
@group_id = 3
|
17
|
+
end
|
18
|
+
|
19
|
+
## Admin singleton methods
|
20
|
+
|
21
|
+
def test_get_login
|
22
|
+
assert_respond_to(Admin, :get_login)
|
23
|
+
assert_nothing_raised{ Admin.get_login }
|
24
|
+
assert_kind_of(String, Admin.get_login)
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_get_user_basic
|
28
|
+
assert_respond_to(Admin, :get_user)
|
29
|
+
assert_nothing_raised{ Admin.get_user(@user) }
|
30
|
+
assert_nothing_raised{ Admin.get_user(@user_id) }
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_get_user_by_name
|
34
|
+
assert_kind_of(User, Admin.get_user(@user))
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_get_user_by_id
|
38
|
+
assert_kind_of(User, Admin.get_user(@user_id))
|
39
|
+
end
|
40
|
+
|
41
|
+
def test_get_user_expected_errors
|
42
|
+
assert_raise(ArgumentError){ Admin.get_user }
|
43
|
+
assert_raise(TypeError){ Admin.get_user([]) }
|
44
|
+
assert_raise(Admin::Error){ Admin.get_user('foofoofoo') }
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_users_basic
|
48
|
+
assert_respond_to(Admin, :users)
|
49
|
+
assert_nothing_raised{ Admin.users }
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_users
|
53
|
+
assert_kind_of(Array, Admin.users)
|
54
|
+
assert_kind_of(User, Admin.users.first)
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_users_block_form
|
58
|
+
array = []
|
59
|
+
assert_nothing_raised{ Admin.users{ |g| array << g } }
|
60
|
+
assert_equal(true, Admin.users.length == array.length)
|
61
|
+
assert_nothing_raised{ Admin.users{ |g| break } }
|
62
|
+
end
|
63
|
+
|
64
|
+
def test_users_expected_errors
|
65
|
+
assert_raise(ArgumentError){ Admin.users(@user_id) }
|
66
|
+
end
|
67
|
+
|
68
|
+
def test_get_group_basic
|
69
|
+
assert_respond_to(Admin, :get_group)
|
70
|
+
assert_nothing_raised{ Admin.get_group(@group) }
|
71
|
+
assert_nothing_raised{ Admin.get_group(@group_id) }
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_get_group_by_name
|
75
|
+
assert_kind_of(Group, Admin.get_group(@group))
|
76
|
+
end
|
77
|
+
|
78
|
+
def test_get_group_by_id
|
79
|
+
assert_kind_of(Group, Admin.get_group(@group_id))
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_get_group_expected_errors
|
83
|
+
assert_raise(ArgumentError){ Admin.get_group }
|
84
|
+
assert_raise(TypeError){ Admin.get_group([]) }
|
85
|
+
assert_raise(Admin::Error){ Admin.get_group('foofoofoo') }
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_groups_basic
|
89
|
+
assert_respond_to(Admin, :groups)
|
90
|
+
assert_nothing_raised{ Admin.groups }
|
91
|
+
end
|
92
|
+
|
93
|
+
def test_groups
|
94
|
+
assert_kind_of(Array, Admin.groups)
|
95
|
+
assert_kind_of(Group, Admin.groups.first)
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_groups_expected_errors
|
99
|
+
assert_raise(ArgumentError){ Admin.groups(@group_id) }
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_groups_block_form
|
103
|
+
array = []
|
104
|
+
assert_nothing_raised{ Admin.groups{ |g| array << g } }
|
105
|
+
assert_equal(true, Admin.groups.length == array.length)
|
106
|
+
assert_nothing_raised{ Admin.groups{ |g| break } }
|
107
|
+
end
|
108
|
+
|
109
|
+
## User Tests
|
110
|
+
|
111
|
+
def test_user_name
|
112
|
+
@user = Admin.users.first
|
113
|
+
assert_respond_to(@user, :name)
|
114
|
+
assert_kind_of(String, @user.name)
|
115
|
+
end
|
116
|
+
|
117
|
+
def test_user_passwd
|
118
|
+
@user = Admin.users.first
|
119
|
+
assert_respond_to(@user, :passwd)
|
120
|
+
assert_kind_of(String, @user.passwd)
|
121
|
+
end
|
122
|
+
|
123
|
+
def test_user_uid
|
124
|
+
@user = Admin.users.first
|
125
|
+
assert_respond_to(@user, :uid)
|
126
|
+
assert_kind_of(Fixnum, @user.uid)
|
127
|
+
end
|
128
|
+
|
129
|
+
def test_user_gid
|
130
|
+
@user = Admin.users.first
|
131
|
+
assert_respond_to(@user, :gid)
|
132
|
+
assert_kind_of(Fixnum, @user.gid)
|
133
|
+
end
|
134
|
+
|
135
|
+
def test_user_dir
|
136
|
+
@user = Admin.users.first
|
137
|
+
assert_respond_to(@user, :dir)
|
138
|
+
assert_kind_of(String, @user.dir)
|
139
|
+
end
|
140
|
+
|
141
|
+
def test_user_shell
|
142
|
+
@user = Admin.users.first
|
143
|
+
assert_respond_to(@user, :shell)
|
144
|
+
assert_kind_of(String, @user.shell)
|
145
|
+
end
|
146
|
+
|
147
|
+
def test_user_gecos
|
148
|
+
@user = Admin.users.first
|
149
|
+
assert_respond_to(@user, :gecos)
|
150
|
+
assert_kind_of(String, @user.gecos)
|
151
|
+
end
|
152
|
+
|
153
|
+
def test_user_quota
|
154
|
+
@user = Admin.users.first
|
155
|
+
assert_respond_to(@user, :quota)
|
156
|
+
assert_true([Fixnum, NilClass].include?(@user.quota.class))
|
157
|
+
end
|
158
|
+
|
159
|
+
def test_user_age
|
160
|
+
@user = Admin.users.first
|
161
|
+
assert_respond_to(@user, :age)
|
162
|
+
assert_true([Fixnum, NilClass].include?(@user.age.class))
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_user_access_class
|
166
|
+
@user = Admin.users.first
|
167
|
+
assert_respond_to(@user, :access_class)
|
168
|
+
assert_true([String, NilClass].include?(@user.access_class.class))
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_user_comment
|
172
|
+
@user = Admin.users.first
|
173
|
+
assert_respond_to(@user, :comment)
|
174
|
+
assert_true([String, NilClass].include?(@user.comment.class))
|
175
|
+
end
|
176
|
+
|
177
|
+
def test_user_expire
|
178
|
+
@user = Admin.users.first
|
179
|
+
assert_respond_to(@user, :expire)
|
180
|
+
assert_true([Time, NilClass].include?(@user.expire.class))
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_user_change
|
184
|
+
@user = Admin.users.first
|
185
|
+
assert_respond_to(@user, :change)
|
186
|
+
assert_true([Time, NilClass].include?(@user.change.class))
|
187
|
+
end
|
188
|
+
|
189
|
+
def test_user_login_time
|
190
|
+
@user = Admin.users.first
|
191
|
+
assert_respond_to(@user, :login_time)
|
192
|
+
assert_true([Time, NilClass].include?(@user.login_time.class))
|
193
|
+
end
|
194
|
+
|
195
|
+
def test_user_login_device
|
196
|
+
@user = Admin.users.first
|
197
|
+
assert_respond_to(@user, :login_device)
|
198
|
+
assert_true([String, NilClass].include?(@user.login_device.class))
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_user_login_host
|
202
|
+
@user = Admin.users.first
|
203
|
+
assert_respond_to(@user, :login_host)
|
204
|
+
assert_true([String, NilClass].include?(@user.login_host.class))
|
205
|
+
end
|
206
|
+
|
207
|
+
def test_user_groups
|
208
|
+
@user = Admin.users.first
|
209
|
+
assert_respond_to(@user, :groups)
|
210
|
+
assert_kind_of(Array, @user.groups)
|
211
|
+
end
|
212
|
+
|
213
|
+
## Group Tests
|
214
|
+
|
215
|
+
def test_group_name
|
216
|
+
@group = Admin.groups.first
|
217
|
+
assert_respond_to(@group, :name)
|
218
|
+
assert_kind_of(String, @group.name)
|
219
|
+
end
|
220
|
+
|
221
|
+
def test_group_gid
|
222
|
+
@group = Admin.groups.first
|
223
|
+
assert_respond_to(@group, :gid)
|
224
|
+
assert_kind_of(Fixnum, @group.gid)
|
225
|
+
end
|
226
|
+
|
227
|
+
def test_group_members
|
228
|
+
@group = Admin.groups.first
|
229
|
+
assert_respond_to(@group, :members)
|
230
|
+
assert_kind_of(Array, @group.members)
|
231
|
+
end
|
232
|
+
|
233
|
+
def test_group_passwd
|
234
|
+
@group = Admin.groups.first
|
235
|
+
assert_respond_to(@group, :passwd)
|
236
|
+
assert_kind_of(String, @group.passwd)
|
237
|
+
end
|
238
|
+
|
239
|
+
def teardown
|
240
|
+
@user = nil
|
241
|
+
@user_id = nil
|
242
|
+
@group = nil
|
243
|
+
@group_id = nil
|
244
|
+
end
|
246
245
|
end
|
metadata
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys-admin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 5
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 5
|
9
|
+
- 3
|
10
|
+
version: 1.5.3
|
5
11
|
platform: ruby
|
6
12
|
authors:
|
7
13
|
- Daniel J. Berger
|
@@ -9,20 +15,26 @@ autorequire:
|
|
9
15
|
bindir: bin
|
10
16
|
cert_chain: []
|
11
17
|
|
12
|
-
date:
|
18
|
+
date: 2010-10-06 00:00:00 -06:00
|
13
19
|
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: test-unit
|
17
|
-
|
18
|
-
|
19
|
-
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
23
|
-
|
24
|
-
|
25
|
-
|
29
|
+
hash: 9
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 1
|
33
|
+
- 1
|
34
|
+
version: 2.1.1
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id001
|
37
|
+
description: " The sys-admin library is a unified, cross platform replacement for the\n 'etc' library that ships as part of the Ruby standard library. It\n provides a common interface for all platforms, including MS Windows. In\n addition, it provides an interface for adding, deleting and configuring\n users on MS Windows.\n"
|
26
38
|
email: djberg96@gmail.com
|
27
39
|
executables: []
|
28
40
|
|
@@ -34,21 +46,23 @@ extra_rdoc_files:
|
|
34
46
|
- MANIFEST
|
35
47
|
- ext/sys/admin.c
|
36
48
|
files:
|
49
|
+
- Rakefile
|
50
|
+
- README
|
37
51
|
- doc/sys-admin-unix.txt
|
38
52
|
- doc/sys-admin-windows.txt
|
53
|
+
- sys-admin.gemspec
|
54
|
+
- CHANGES
|
39
55
|
- examples/groups.rb
|
40
56
|
- examples/users.rb
|
41
|
-
- test/test_sys_admin.rb
|
42
|
-
- test/test_sys_admin_unix.rb
|
43
57
|
- test/test_sys_admin_windows.rb
|
44
|
-
-
|
58
|
+
- test/test_sys_admin_unix.rb
|
59
|
+
- test/test_sys_admin.rb
|
45
60
|
- MANIFEST
|
46
|
-
- Rakefile
|
47
|
-
- README
|
48
61
|
- ext/sys/admin.c
|
49
62
|
- ext/sys/admin.h
|
63
|
+
- ext/extconf.rb
|
50
64
|
has_rdoc: true
|
51
|
-
homepage: http://www.
|
65
|
+
homepage: http://www.github.com/djberg96/sysutils
|
52
66
|
licenses:
|
53
67
|
- Artistic 2.0
|
54
68
|
post_install_message:
|
@@ -57,21 +71,27 @@ rdoc_options: []
|
|
57
71
|
require_paths:
|
58
72
|
- lib
|
59
73
|
required_ruby_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
60
75
|
requirements:
|
61
76
|
- - ">="
|
62
77
|
- !ruby/object:Gem::Version
|
63
|
-
|
64
|
-
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
65
82
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
66
84
|
requirements:
|
67
85
|
- - ">="
|
68
86
|
- !ruby/object:Gem::Version
|
87
|
+
hash: 3
|
88
|
+
segments:
|
89
|
+
- 0
|
69
90
|
version: "0"
|
70
|
-
version:
|
71
91
|
requirements: []
|
72
92
|
|
73
93
|
rubyforge_project: sysutils
|
74
|
-
rubygems_version: 1.3.
|
94
|
+
rubygems_version: 1.3.7
|
75
95
|
signing_key:
|
76
96
|
specification_version: 3
|
77
97
|
summary: A unified, cross platform replacement for the "etc" library.
|