sys-admin 1.4.1 → 1.4.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,11 @@
1
+ == 1.4.2 - 26-Jun-2007
2
+ * Fixed a bug in the Admin.get_login method where it would return junk
3
+ if the underlying getlogin() function failed (Unix). Thanks go to Gonzalo
4
+ Garramuno for the spot. This bug also resulted in some refactoring of the
5
+ underlying C code.
6
+ * Removed the install.rb file. The logic in that file has been moved directly
7
+ into the Rakefile.
8
+
1
9
  == 1.4.1 - 21-Mar-2007
2
10
  * Bug fix for OS X. Thanks go to an anonymous user for the spot.
3
11
  * Added a Rakefile. Building, testing and installing should now use the
data/MANIFEST CHANGED
@@ -1,19 +1,14 @@
1
- * install.rb
2
1
  * sys-admin.gemspec
3
2
  * CHANGES
4
3
  * MANIFEST
5
4
  * Rakefile
6
5
  * README
7
-
8
6
  * examples/groups.rb
9
7
  * examples/users.rb
10
-
11
8
  * ext/admin.c
12
9
  * ext/admin.h
13
10
  * ext/extconf.rb
14
-
15
- * lib/sys/win32.rb
16
-
11
+ * lib/sys/admin.rb
17
12
  * test/tc_admin.rb
18
13
  * test/tc_unix.rb
19
- * test/tc_windows.rb
14
+ * test/tc_windows.rb
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rake/testtask'
4
+ require 'rbconfig'
5
+ include Config
4
6
 
5
7
  desc "Clean the build files for the sys-admin source for UNIX systems"
6
8
  task :clean do
@@ -27,12 +29,14 @@ task :build => [:clean] do
27
29
  end
28
30
 
29
31
  if RUBY_PLATFORM.match('mswin')
30
- desc "Install the sys-admin package"
32
+ desc "Install the sys-admin package for MS Windows"
31
33
  task :install do
32
- sh 'ruby install.rb'
34
+ install_dir = File.join(CONFIG['sitelibdir'], 'sys')
35
+ Dir.mkdir(install_dir) unless File.exists?(install_dir)
36
+ FileUtils.cp('lib/sys/admin.rb', install_dir, :verbose => true)
33
37
  end
34
38
  else
35
- desc "Install the sys-admin package"
39
+ desc "Install the sys-admin package for Unix platforms"
36
40
  task :install => [:build] do
37
41
  Dir.chdir('ext') do
38
42
  sh 'make install'
data/ext/admin.c CHANGED
@@ -39,42 +39,64 @@ static VALUE group_init(VALUE self){
39
39
  * call-seq:
40
40
  * Sys::Admin.get_login
41
41
  *
42
- * Returns the login for the process. If this is called from a process that
43
- * has no controlling terminal, then it resorts to returning the "USER"
44
- * environment variable. If that still isn't defined, nil is returned.
42
+ * Returns the login for the process. If this is called from a process that
43
+ * has no controlling terminal, then it resorts to returning the "LOGNAME" or
44
+ * "USER" environment variable. If neither of those is defined, then nil
45
+ * is returned.
45
46
  *
46
- *--
47
- * Developer's Note:
48
- *
49
- * Uses the (POSIX) reentrant version of getlogin_r() if supported. Otherwise
50
- * it resorts to the standard getlogin() function. If that fails, it resorts
51
- * to cuserid(). If that fails, it resorts to getenv("USER"). If that fails,
52
- * then nil is returned.
47
+ * Note that this method will _probably_ return the real user login, but may
48
+ * return the effective user login. YMMV depending on your platform and how
49
+ * the program is run.
53
50
  */
54
51
  static VALUE admin_get_login(VALUE klass){
55
- char login[_POSIX_LOGIN_NAME_MAX];
56
52
  VALUE v_login = Qnil;
57
53
 
58
54
  #ifdef HAVE_GETLOGIN_R
59
- getlogin_r(login, sizeof(login));
55
+ char login[_POSIX_LOGIN_NAME_MAX];
56
+
57
+ if(!getlogin_r(login, _POSIX_LOGIN_NAME_MAX))
58
+ return rb_str_new2(login);
60
59
  #elif HAVE_GETLOGIN
61
- strcpy(login, getlogin());
60
+ char* login = getlogin();
61
+
62
+ if(login)
63
+ return rb_str_new2(login);
62
64
  #endif
63
65
 
64
- #ifdef HAVE_CUSERID
65
- if(!login)
66
- cuserid(login);
66
+ #ifdef HAVE_GETPWUID_R
67
+ uid_t uid;
68
+ char buf[USER_BUF_SIZE];
69
+ struct passwd pwd;
70
+ struct passwd* pwdbuf;
71
+
72
+ uid = getuid();
73
+
74
+ if(getpwuid_r(uid, &pwd, buf, USER_BUF_SIZE, &pwdbuf) != 0)
75
+ return rb_str_new2(pwdbuf->pw_name);
76
+ #elif HAVE_GETPWUID
77
+ uid_t uid;
78
+ struct passwd* pwd;
79
+
80
+ uid = getuid();
81
+
82
+ if((pwd = getpwuid(uid)))
83
+ return rb_str_new2(pwd->pw_name);
67
84
  #endif
68
85
 
69
86
  #ifdef HAVE_GETENV
70
- if(!login)
71
- strcpy(login, getenv("USER"));
72
- #endif
87
+ char* user = getenv("LOGNAME");
73
88
 
74
- if(login)
75
- v_login = rb_str_new2(login);
89
+ if(user){
90
+ return rb_str_new2(user);
91
+ }
92
+ else{
93
+ user = getenv("USER");
94
+ if(user)
95
+ return rb_str_new2(user);
96
+ }
97
+ #endif
76
98
 
77
- return v_login;
99
+ return Qnil;
78
100
  }
79
101
 
80
102
  /* call-seq:
data/ext/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.4.1"
11
+ #define SYS_ADMIN_VERSION "1.4.2"
12
12
 
13
13
  #ifdef HAVE_LASTLOG_H
14
14
  #include <lastlog.h>
data/ext/extconf.rb CHANGED
@@ -1,8 +1,8 @@
1
1
  require "mkmf"
2
2
 
3
3
  if RUBY_PLATFORM.match('mswin')
4
- STDERR.puts "Use the install.rb file on Win32 systems."
5
- STDERR.puts "Exiting. The sys-admin package was NOT installed."
4
+ STDERR.puts "Use the 'rake install' task to install on MS Windows."
5
+ STDERR.puts "Exiting. The sys-admin package was NOT installed."
6
6
  exit
7
7
  else
8
8
  dir_config('admin')
@@ -11,8 +11,6 @@ else
11
11
  have_func("getlogin")
12
12
  have_func("getenv")
13
13
 
14
- have_func("cuserid")
15
-
16
14
  have_func("getpwuid_r")
17
15
  have_func("getpwuid")
18
16
  have_func("getpwnam_r")
data/test/tc_unix.rb CHANGED
@@ -17,7 +17,7 @@ class TC_Sys_Admin_Unix < Test::Unit::TestCase
17
17
  end
18
18
 
19
19
  def test_version
20
- assert_equal("1.4.1", Admin::VERSION)
20
+ assert_equal("1.4.2", Admin::VERSION)
21
21
  end
22
22
 
23
23
  def test_get_login
data/test/tc_windows.rb CHANGED
@@ -24,7 +24,7 @@ class TC_Sys_Admin_Win32 < Test::Unit::TestCase
24
24
  end
25
25
 
26
26
  def test_version
27
- assert_equal("1.4.1", Admin::VERSION)
27
+ assert_equal("1.4.2", Admin::VERSION)
28
28
  end
29
29
 
30
30
  def test_01_add_local_user
metadata CHANGED
@@ -1,10 +1,10 @@
1
1
  --- !ruby/object:Gem::Specification
2
- rubygems_version: 0.9.2
2
+ rubygems_version: 0.9.4
3
3
  specification_version: 1
4
4
  name: sys-admin
5
5
  version: !ruby/object:Gem::Version
6
- version: 1.4.1
7
- date: 2007-03-22 00:00:00 -06:00
6
+ version: 1.4.2
7
+ date: 2007-06-26 00:00:00 -06:00
8
8
  summary: A unified, cross platform replacement for the "etc" package.
9
9
  require_paths:
10
10
  - lib
@@ -38,9 +38,9 @@ files:
38
38
  - MANIFEST
39
39
  - README
40
40
  - Rakefile
41
- - ext/extconf.rb
42
41
  - ext/admin.c
43
42
  - ext/admin.h
43
+ - ext/extconf.rb
44
44
  test_files:
45
45
  - test/tc_admin.rb
46
46
  rdoc_options: []