Skip to content

Commit d2e822d

Browse files
author
Adam Palmblad
committed
Fixes for rubinius and tests.
1 parent cc33321 commit d2e822d

File tree

5 files changed

+57
-30
lines changed

5 files changed

+57
-30
lines changed

HISTORY

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
[2015/10/06]
2+
* Version 2.5.0
3+
- fixes for compiling for rubinius, at long last
4+
- TESTS
5+
- add a few method aliases
6+
17
[2014/12/02]
28
* Version 2.4.1
39
- sp_loginclass support should NOT have been added to password implementation

README

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,21 @@ make # use gmake on FreeBSD
2626
still present, but no promises about earlier versions of Ruby.
2727

2828
3. Shadow::Passwd module's methods
29-
_________________________________________________________
30-
Method | Linux | Solaris | OS X | *BSD
31-
_________________________________________________________
32-
getspent | * | * | * | *
33-
getspnam(name) | * | * | * | *
29+
________________________________________________________________________
30+
Method | Linux | Solaris | OS X | *BSD
31+
________________________________________________________________________
32+
getspent | * | * | * | *
33+
getspnam(name) | * | * | * | *
3434
from_user_name(name) (alias of above) | * | * | * | *
35-
setspent | * | * | * | *
36-
endspent | * | * | * | *
37-
fgetspent(file) | * | * | N | N
38-
sgetspent(str) | * | N | N | N
39-
putspent(entry,file) | * | * | N | N
40-
add_password_entry (alias of above ) | * | * | N | N
41-
lckpwdf,lock | * | * | N | N
42-
ulckpwdf,unlock | * | * | N | N
43-
lock? | * | * | N | N
35+
setspent | * | * | * | *
36+
endspent | * | * | * | *
37+
fgetspent(file) | * | * | N | N
38+
sgetspent(str) | * | N | N | N
39+
putspent(entry,file) | * | * | N | N
40+
add_password_entry (alias of above ) | * | * | N | N
41+
lckpwdf,lock | * | * | N | N
42+
ulckpwdf,unlock | * | * | N | N
43+
lock? | * | * | N | N
4444

4545
Check the implementation in use via Shadow::IMPLEMENTATION.
4646

ruby-shadow.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
1919
spec.name = 'ruby-shadow'
2020
spec.required_ruby_version = ['>= 1.8']
2121
spec.summary = '*nix Shadow Password Module'
22-
spec.version = '2.4.1'
22+
spec.version = '2.5.0'
2323
spec.license = "Public Domain License"
2424
end

shadow/shadow.c

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -144,21 +144,27 @@ rb_shadow_putspent(VALUE self, VALUE entry, VALUE file)
144144

145145
if( TYPE(file) != T_FILE )
146146
rb_raise(rb_eTypeError,"argument must be a File.");
147-
147+
/*
148148
for(i=0; i<NUM_FIELDS; i++)
149-
val[i] = RSTRUCT_PTR( entry )[i]; //val[i] = RSTRUCT(entry)->ptr[i];
149+
{
150+
val[i] = rb_ary_entry( entry, i ); //val[i] = RSTRUCT(entry)->ptr[i];
151+
i//val[i] = rb_struct_aref( entry, i );
152+
}
153+
*/
150154
cfile = file_ptr( RFILE(file)->fptr );
151155

152-
153-
centry.sp_namp = StringValuePtr(val[0]);
154-
centry.sp_pwdp = StringValuePtr(val[1]);
155-
centry.sp_lstchg = FIX2INT(val[2]);
156-
centry.sp_min = FIX2INT(val[3]);
157-
centry.sp_max = FIX2INT(val[4]);
158-
centry.sp_warn = FIX2INT(val[5]);
159-
centry.sp_inact = FIX2INT(val[6]);
160-
centry.sp_expire = FIX2INT(val[8]);
161-
centry.sp_flag = FIX2INT(val[9]);
156+
VALUE x = rb_ary_entry( entry, 0 );
157+
centry.sp_namp = StringValuePtr( x );
158+
x = rb_ary_entry( entry, 1 );
159+
centry.sp_pwdp = StringValuePtr( x );
160+
centry.sp_lstchg = FIX2INT( rb_ary_entry( entry, 2) );
161+
centry.sp_min = FIX2INT( rb_ary_entry( entry, 3 ) );
162+
centry.sp_max = FIX2INT( rb_ary_entry( entry, 4 ) );
163+
centry.sp_warn = FIX2INT( rb_ary_entry( entry, 5 ));
164+
centry.sp_inact = FIX2INT( rb_ary_entry( entry, 6 ) );
165+
// missing 7 I think is put in to deal with beign similar to BSD returns, for the value pw_change.
166+
centry.sp_expire = FIX2INT( rb_ary_entry( entry, 8 ) );
167+
centry.sp_flag = FIX2INT( rb_ary_entry( entry, 9 ) );
162168

163169
result = putspent(&centry,cfile);
164170

test/basic_test.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
require 'test/unit'
22
require 'rubygems'
33
require 'shadow'
4+
require 'stringio'
45
class RubyShadowTest < Test::Unit::TestCase
56
STRUCT_METHODS = %w( sp_namp sp_pwdp sp_lstchg sp_min sp_max sp_warn sp_inact sp_expire sp_loginclass )
67
# --------------------------------------------------- test_smoke_test_getspent
78
def test_smoke_test_getspent
89
x = Shadow::Passwd.getspent
10+
assert( x, "ensure you have permissions to check this (sudo?)" )
911
check_struct( x )
1012
end
1113
# ----------------------------------------------------- test_getspnam_for_user
1214
def test_getspnam_for_user
1315
user = `whoami`.strip
1416
x = Shadow::Passwd.getspnam( user )
17+
assert( x, "ensure you have permissions to check this (sudo?)" )
1518
check_struct( x )
1619
end
1720
# ---------------------------------------- test_getspnam_for_non_existent_user
@@ -20,11 +23,12 @@ def test_getspnam_for_non_existent_user
2023
end
2124
# -------------------------------------------------------------- test_putspent
2225
def test_putspent
23-
omit_if( Shadow::IMPLEMENTATION != 'SHADOW' )
24-
result = StringIO.open( '', 'w' ) do |fh|
26+
omit_if( Shadow::IMPLEMENTATION != 'SHADOW' ) if respond_to?( :omit_if )
27+
#result = StringIO.open( '', 'w' ) do |fh|
28+
File.open( 'test_password', 'w' ) do |fh|
2529
Shadow::Passwd.add_password_entry( sample_entry, fh )
2630
end
27-
raise result.inspect
31+
assert( File.read( 'test_password' ).match( sample_entry.first ) )
2832
end
2933
# --------------------------------------------------------------- check_struct
3034
def check_struct( s )
@@ -34,6 +38,17 @@ def check_struct( s )
3438
end
3539
# ----------------------------------------------------------------- test_entry
3640
def sample_entry( &block )
41+
return ['test_user', # sp_namp
42+
'new_pass', # sp_pwdp
43+
0, #sp_lastchg
44+
0, #sp_min
45+
0, #sp_max
46+
0, #sp_warn
47+
0, #sp_inact
48+
0, #????
49+
0, #sp_expire
50+
0 # sp_flag
51+
]
3752
e = Shadow::Passwd::Entry.new
3853
e.sp_namp = 'test_user'
3954
e.sp_pwdp = 'password'

0 commit comments

Comments
 (0)