sys-admin 1.5.3 → 1.5.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,6 @@
1
+ == 1.5.4 - 7-Oct-2010
2
+ * Prefer the getlastlogx() function over lastlog() where supported.
3
+
1
4
  == 1.5.3 - 6-Oct-2010
2
5
  * Refactored the Rakefile. The old installation tasks have been replaced
3
6
  with gem build and install tasks. In addition, the platform handling has
data/Rakefile CHANGED
@@ -10,6 +10,7 @@ task :clean do
10
10
  Dir['*.gem'].each{ |f| File.delete(f) } # Remove any .gem files
11
11
  unless WINDOWS
12
12
  Dir.chdir('ext') do
13
+ rm_rf('conftest.dSYM') if File.exists?('conftest.dSYM') # OS X
13
14
  build_file = 'admin.' + Config::CONFIG['DLEXT']
14
15
  sh 'make distclean' if File.exists?(build_file)
15
16
  File.delete("sys/#{build_file}") if File.exists?("sys/#{build_file}")
data/ext/extconf.rb CHANGED
@@ -39,12 +39,16 @@ else
39
39
  utmp = have_header("utmp.h")
40
40
  lastlog = have_header("lastlog.h")
41
41
 
42
+ if have_header("utmpx.h")
43
+ have_func("getlastlogx")
44
+ end
45
+
42
46
  if utmp || lastlog
43
- have_struct_member(
44
- "struct lastlog",
45
- "ll_time",
46
- ["utmp.h", "time.h", "lastlog.h"]
47
- )
47
+ have_struct_member(
48
+ "struct lastlog",
49
+ "ll_time",
50
+ ["utmp.h", "time.h", "lastlog.h"]
51
+ )
48
52
  end
49
53
 
50
54
  $CFLAGS += " -D_POSIX_PTHREAD_SEMANTICS"
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.3"
11
+ #define SYS_ADMIN_VERSION "1.5.4"
12
12
 
13
13
  #if defined(__MACH__) || defined(__APPLE__)
14
14
  #define __BSD__
@@ -18,11 +18,15 @@
18
18
  #define __BSD__
19
19
  #endif
20
20
 
21
+ #if defined(HAVE_UTMPX_H) && defined(HAVE_GETLASTLOGX)
22
+ #include <utmpx.h>
23
+ #else
21
24
  #ifdef HAVE_LASTLOG_H
22
25
  #include <lastlog.h>
23
26
  #else
24
27
  #include <utmp.h>
25
28
  #endif
29
+ #endif
26
30
 
27
31
  #ifndef _POSIX_LOGIN_NAME_MAX
28
32
  #define _POSIX_LOGIN_NAME_MAX 9
@@ -422,34 +426,44 @@ void get_group_from_value(VALUE v_group, struct group* grp){
422
426
  * still be empty or nil.
423
427
  */
424
428
  int get_lastlog_info(struct passwd* pwd, VALUE v_user){
425
- int fd;
426
- ssize_t bytes_read;
427
- struct lastlog log;
428
- int ll_size = sizeof(struct lastlog);
429
-
430
- /* The lastlog information is not necessarily readable by all users, so
431
- * ignore open() errors if they occur.
432
- */
433
- if((fd = open(_PATH_LASTLOG, O_RDONLY)) == -1)
434
- return -1;
435
-
436
- if((bytes_read = pread(fd, &log, ll_size, pwd->pw_uid * ll_size)) < 0){
437
- close(fd);
438
- rb_raise(cAdminError, "%s", strerror(errno));
439
- }
429
+ #ifdef HAVE_GETLASTLOGX
430
+ struct lastlogx log;
431
+
432
+ if(getlastlogx(pwd->pw_uid, &log)){
433
+ rb_iv_set(v_user, "@login_time", rb_time_new(log.ll_tv.tv_sec, log.ll_tv.tv_usec));
434
+ rb_iv_set(v_user, "@login_device", rb_str_new2(log.ll_line));
435
+ rb_iv_set(v_user, "@login_host", rb_str_new2(log.ll_host));
436
+ }
437
+ #else
438
+ int fd;
439
+ ssize_t bytes_read;
440
+ struct lastlog log;
441
+ int ll_size = sizeof(struct lastlog);
442
+
443
+ /* The lastlog information is not necessarily readable by all users, so
444
+ * ignore open() errors if they occur.
445
+ */
446
+ if((fd = open(_PATH_LASTLOG, O_RDONLY)) == -1)
447
+ return -1;
448
+
449
+ if((bytes_read = pread(fd, &log, ll_size, pwd->pw_uid * ll_size)) < 0){
450
+ close(fd);
451
+ rb_raise(cAdminError, "%s", strerror(errno));
452
+ }
440
453
 
441
- close(fd);
454
+ close(fd);
442
455
 
443
- if(bytes_read > 0){
456
+ if(bytes_read > 0){
444
457
  #ifdef HAVE_ST_LL_TIME
445
- if(log.ll_time != 0)
446
- rb_iv_set(v_user, "@login_time", rb_time_new(log.ll_time, 0));
458
+ if(log.ll_time != 0)
459
+ rb_iv_set(v_user, "@login_time", rb_time_new(log.ll_time, 0));
460
+ #endif
461
+ rb_iv_set(v_user, "@login_device", rb_str_new2(log.ll_line));
462
+ rb_iv_set(v_user, "@login_host", rb_str_new2(log.ll_host));
463
+ }
447
464
  #endif
448
- rb_iv_set(v_user, "@login_device", rb_str_new2(log.ll_line));
449
- rb_iv_set(v_user, "@login_host", rb_str_new2(log.ll_host));
450
- }
451
465
 
452
- return 0;
466
+ return 0;
453
467
  }
454
468
 
455
469
  /*
data/sys-admin.gemspec CHANGED
@@ -4,7 +4,7 @@ require 'rubygems'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'sys-admin'
7
- spec.version = '1.5.3'
7
+ spec.version = '1.5.4'
8
8
  spec.author = 'Daniel J. Berger'
9
9
  spec.license = 'Artistic 2.0'
10
10
  spec.email = 'djberg96@gmail.com'
@@ -16,6 +16,6 @@ end
16
16
 
17
17
  class TC_Sys_Admin_All < Test::Unit::TestCase
18
18
  def test_version
19
- assert_equal('1.5.3', Sys::Admin::VERSION)
19
+ assert_equal('1.5.4', Sys::Admin::VERSION)
20
20
  end
21
21
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sys-admin
3
3
  version: !ruby/object:Gem::Version
4
- hash: 5
4
+ hash: 11
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
8
  - 5
9
- - 3
10
- version: 1.5.3
9
+ - 4
10
+ version: 1.5.4
11
11
  platform: ruby
12
12
  authors:
13
13
  - Daniel J. Berger
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-10-06 00:00:00 -06:00
18
+ date: 2010-10-07 00:00:00 -06:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -46,21 +46,21 @@ extra_rdoc_files:
46
46
  - MANIFEST
47
47
  - ext/sys/admin.c
48
48
  files:
49
- - Rakefile
50
- - README
49
+ - CHANGES
51
50
  - doc/sys-admin-unix.txt
52
51
  - doc/sys-admin-windows.txt
53
- - sys-admin.gemspec
54
- - CHANGES
55
52
  - examples/groups.rb
56
53
  - examples/users.rb
57
- - test/test_sys_admin_windows.rb
58
- - test/test_sys_admin_unix.rb
59
- - test/test_sys_admin.rb
60
- - MANIFEST
54
+ - ext/extconf.rb
61
55
  - ext/sys/admin.c
62
56
  - ext/sys/admin.h
63
- - ext/extconf.rb
57
+ - MANIFEST
58
+ - Rakefile
59
+ - README
60
+ - sys-admin.gemspec
61
+ - test/test_sys_admin.rb
62
+ - test/test_sys_admin_unix.rb
63
+ - test/test_sys_admin_windows.rb
64
64
  has_rdoc: true
65
65
  homepage: http://www.github.com/djberg96/sysutils
66
66
  licenses: