pax_global_header00006660000000000000000000000064126050334260014513gustar00rootroot0000000000000052 comment=d2e822d8a8bda61f0774debbfce363a7347ed893 ruby-shadow-2.5.0/000077500000000000000000000000001260503342600137635ustar00rootroot00000000000000ruby-shadow-2.5.0/.gitignore000066400000000000000000000001051260503342600157470ustar00rootroot00000000000000Makefile mkmf.log ruby-shadow-*.gem shadow.o shadow.so shadow.bundle ruby-shadow-2.5.0/HISTORY000066400000000000000000000060261260503342600150530ustar00rootroot00000000000000[2015/10/06] * Version 2.5.0 - fixes for compiling for rubinius, at long last - TESTS - add a few method aliases [2014/12/02] * Version 2.4.1 - sp_loginclass support should NOT have been added to password implementation [2014/12/01] * Version 2.4.0 - Add support for sp_loginclass via pwd.h [2014/04/28] * Version 2.3.3 - Added support for more BSDs, thanks to https://github.com/bsiegert. - Simplified compatibility check, removing check for function not actually used in pwd.h implementations. [2014/02/25] [2013/12/18] * Version 2.3.3 Fix bug in shadow implementations (Linux, solaris) where sp_expired field was incorrectly set as nil. -1 is used to indicate not set. This was introduced 2.3.0. [2013/11/13] * Version 2.3.1 - Caleb Land Remove sgetspent on implementations using pwd.h [2013/11/13] * Version 2.3.0 - Caleb Land Merge OS X work into main gem. Fix bugs with OS X implementation and tweak support for FreeBSD. See https://github.com/caleb/ruby-shadow/commit/20d98b7d9e3bbbef0b737affd3245590096a316c - Add license file to Manifest. [2013/02/25] - Adam Palmblad Fix compilation issues with ruby 2. [2012/04/17] * Version 2.1.4 - MATSUU Takuto Change obsolete C function to its proper replacement. * Version 2.1.3 - MATSUU Takuto Fix a typo in the C code for rb_shadow_putspent. Typo has been present since ruby 1.9 code was added. [2011/02/08] * Version 2.1.2 - Jeff Blaine <>, Adam Palmblad : Fix issues with compiling against Solaris. Apparently solaris does not offer sgetspent compiling against ruby 1.8; fixes were made to the ruby header path. [2011/02/08] * Version 2.1.1 - Eric Hankins : Looks like there was a minor bug in compiling against ruby 1.8; fixes were made to the ruby header path. [2011/01/27] * Version 2.1 - Ian Marlier : Make ruby-shadow compile under Ruby 1.9.2 * STR2CSTR macro was removed in Ruby 1.9.2, after being deprecated in Ruby 1.8. Change to StringValuePtr() in its place. [2010/07/27] * Version 2.0 - Adam Palmblad : Make ruby-shadow compile under Ruby 1.9 [1999/08/18] * version 1.4.1 - extconf.rb supports glibc2(libc6). [1999/03/09] * version 1.4 - require ruby-1.3 or later version. - sShadowPasswd,mShadow,eFileLock was renamed. - FileLock class is inner class of Shadow Module. - lock,unlock was changed. - lock? method was added. - getspent,fgetspent doesn't raise EOFError - class hierarchy was changed. Shadow Module + Passwd Module + Entry Structure + Group Module (not implemented yet) + Entry Structure (not implemented yet) + FileLock Class [1998/12/17] * version 1.3 - require ruby-1.1d0 or later version. [1998/10/31] * version 1.2 - only some bug fix. [1998/08/31] * version 1.1 - structure Shadow::ShadowPasswd is added. [1998/07/15] * version 1.0 released. ruby-shadow-2.5.0/LICENSE000066400000000000000000000002161260503342600147670ustar00rootroot00000000000000License: Free for any use with your own risk! OR The terms of the Public Domain License (http://creativecommons.org/licenses/publicdomain/) ruby-shadow-2.5.0/MANIFEST000066400000000000000000000002001260503342600151040ustar00rootroot00000000000000extconf.rb HISTORY LICENSE MANIFEST README README.euc ruby-shadow.gemspec pwd/shadow.c pwd/depend shadow/shadow.c shadow/depend ruby-shadow-2.5.0/README000066400000000000000000000072631260503342600146530ustar00rootroot00000000000000Shadow Password module Copyright (C) 1998-1999 Takaaki Tateishi Modified at: <1999/8/19 06:47:14 by ttate> License: See LICENSE 1. What's this This module provides tools to read, and, on Linux, append, information related to password files. Recent versions work on both Linux, Solaris, OS X, FreeBSD and OpenBSD. The functions found are translated to their equivalents in libshadow. Note 2. install ruby extconf.rb make # use gmake on FreeBSD (make install) * Note: Version 2 was developed to compile on Ruby 1.9. 1.8 compatibility should be still present, but no promises about earlier versions of Ruby. 3. Shadow::Passwd module's methods ________________________________________________________________________ Method | Linux | Solaris | OS X | *BSD ________________________________________________________________________ getspent | * | * | * | * getspnam(name) | * | * | * | * from_user_name(name) (alias of above) | * | * | * | * setspent | * | * | * | * endspent | * | * | * | * fgetspent(file) | * | * | N | N sgetspent(str) | * | N | N | N putspent(entry,file) | * | * | N | N add_password_entry (alias of above ) | * | * | N | N lckpwdf,lock | * | * | N | N ulckpwdf,unlock | * | * | N | N lock? | * | * | N | N Check the implementation in use via Shadow::IMPLEMENTATION. 4. Structure Shadow::Passwd::Entry (Struct::PasswdEntry) sp_namp - pointer to null-terminated user name. sp_pwdp - pointer to null-terminated password. sp_lstchg - days since Jan 1, 1970 password was last changed. sp_min - days before which password may not be changed. sp_max - days after which password must be changed. sp_warn - days before password is to expire that user is warned of pending password expiration. sp_inact - days after password expires that account is considered inactive and disabled. sp_expire - days since Jan 1, 1970 when account will be disabled sp_loginclass - pointer to null-terminated user login class. 5. Description getspent, getspname, fgetspent and sgetspent each return a structure Shadow::Passwd::Entry. getspent returns the next entry from the file, and fgetspent returns the next entry from the given stream. sgetspent returns a structure Shadow::Passwd::Entry using the provided string as input. getspnam searches from the current position in the file for an entry matching name. if you get EOF from each operation, you will get nil. setspent and endspent may be used to begin and end, respe- ctively, access to the shadow password file. lckpwdf(lock) and ulckpwdf(unlock) methods should be used to insure exclusive access to the /etc/shadow file. when either method fail, Exception Shadow::FileLock is raised. if you use lock as the iterator, unlock is automatically called when you exit the iterator block. 6. Reference * man shadow * /usr/include/shadow.h * Code at https://github.com/apalmblad/ruby-shadow Original Author: Takaaki Tateishi This GitHub repository is maintained by Adam Palmblad . I'll do my best to keep the repository reasonably up-to-date if you care to send pull requests. ruby-shadow-2.5.0/README.euc000066400000000000000000000040221260503342600154140ustar00rootroot00000000000000Shadow Password module Copyright (C) 1998-1999 Takaaki Tateishi Modified at: <1999/8/19 06:48:01 by ttate> License: Free for any use with your own risk! 1. 概要 linuxにおいてshadow passwordファイルを扱うため のモジュール。 2. インストール ruby extconf.rb make make install * 注意 shadow-1.3ではruby-1.3もしくはそれ以降のバージョン が必要です。 3. Shadow::Passwdモジュールのメソッド達 getspent getspnam(name) setspent endspent fgetspent(file) sgetspent(str) putspent(entry,file) lckpwdf,lock ulckpwdf,unlock lock? 4. Structure Shadow::Passwd::Entry (Struct::PasswdEntry) sp_namp - pointer to null-terminated user name. sp_pwdp - pointer to null-terminated password. sp_lstchg - days since Jan 1, 1970 password was last changed. sp_min - days before which password may not be changed. sp_max - days after which password must be changed. sp_warn - days before password is to expire that user is warned of pending password expiration. sp_inact - days after password expires that account is considered inactive and disabled. sp_expire - days since Jan 1, 1970 when account will be 5. 説明 getspent, getspname, fgetspent, sgetspentはShadow::Passwd::Entry ストラクチャを返します。getspent はファイルから次のパスワ ードエントリを返し、fgetspent は与えられたIOから次のエント リを返します。sgetspentは与えられた文字列からShadow::Passwd::Entry ストラクチャを返します。getspnamはユーザ名を与えると/etc/shadow からそのユーザのShadow::Passwd::Entryストラクチャを返します。 ファイルの終端に達するとnilの値を返します。 setspent,endspentはそれぞれ、ファイルへのアクセスのはじめと おわりに使います。 lckpwdf(lock),ulckpwdf(unlock)は/etc/shadowへの排他的アクセス を実現するためにあります。 lockに失敗するとShadow::FileLockという例外を発生させます。 lockをイテレータとして使うことによって、イテレータブロックを抜ける ときに自動的にunlockを行ないます。 6. 参考 * man shadow * /usr/include/shadow.h ttate@jaist.ac.jp ruby-shadow-2.5.0/extconf.rb000066400000000000000000000030561260503342600157620ustar00rootroot00000000000000# -*- ruby -*- # extconf.rb # # Modified at: <1999/8/19 06:38:55 by ttate> # require 'mkmf' require 'rbconfig' $CFLAGS = case RUBY_VERSION when /^1\.9/; '-DRUBY19' when /^2\./; '-DRUBY19' else; '' end implementation = case CONFIG['host_os'] when /linux/i; 'shadow' when /sunos|solaris/i; 'shadow' when /freebsd|mirbsd|netbsd|openbsd/i; 'pwd' when /darwin/i; 'pwd' else; nil "This library works on OS X, FreeBSD, MirBSD, NetBSD, OpenBSD, Solaris and Linux." end ok = true case implementation when 'shadow' #$LDFLAGS = "-lshadow" if( ! (ok &= have_library("shadow","getspent")) ) $LDFLAGS = "" ok = have_func("getspent") end ok &= have_func("fgetspent") ok &= have_func("setspent") ok &= have_func("endspent") ok &= have_func("lckpwdf") ok &= have_func("ulckpwdf") if ok if !have_func("sgetspent") $CFLAGS += ' -DSOLARIS' end end when 'pwd' ok &= have_func("endpwent") ok &= have_func("getpwent") ok &= have_func("getpwnam") ok &= have_func("getpwuid") ok &= have_func("setpassent") ok &= have_func("setpwent") have_header("uuid/uuid.h") have_header("uuid.h") else ok = false end have_header( "ruby/io.h") if ok create_makefile("shadow", implementation) else raise "You are missing some of the required functions from either shadow.h on Linux/Solaris, or pwd.h on FreeBSD/MirBSD/NetBSD/OpenBSD/OS X." end ruby-shadow-2.5.0/pwd/000077500000000000000000000000001260503342600145555ustar00rootroot00000000000000ruby-shadow-2.5.0/pwd/depend000066400000000000000000000000231260503342600157320ustar00rootroot00000000000000shadow.o: shadow.c ruby-shadow-2.5.0/pwd/shadow.c000066400000000000000000000072401260503342600162110ustar00rootroot00000000000000/* * shadow.c * * Ruby extention module for using FreeBSD/OpenBSD/OS X pwd.h. * * Copyright (C) 1998-1999 by Takaaki.Tateishi(ttate@jaist.ac.jp) * License: Free for any use with your own risk! */ #include #include #include #ifdef HAVE_UUID_UUID_H #include #elif HAVE_UUID_H #include #endif #define PWTYPE struct passwd #include "ruby.h" #ifdef HAVE_RUBY_IO_H #include "ruby/io.h" #else #include "rubyio.h" #endif #ifdef RUBY19 #define file_ptr(x) (x)->stdio_file #else #define file_ptr(x) (x)->f #endif static VALUE rb_mShadow; static VALUE rb_mPasswd; static VALUE rb_sPasswdEntry; static VALUE rb_mGroup; static VALUE rb_sGroupEntry; static VALUE rb_eFileLock; static VALUE rb_shadow_setspent(VALUE self) { setpassent(1); return Qnil; } static VALUE rb_shadow_endspent(VALUE self) { endpwent(); return Qnil; } static VALUE convert_pw_struct( struct passwd *entry ) { /* Hmm. Why custom pw_change instead of sp_lstchg? */ return rb_struct_new(rb_sPasswdEntry, rb_tainted_str_new2(entry->pw_name), /* sp_namp */ rb_tainted_str_new2(entry->pw_passwd), /* sp_pwdp, encryped password */ Qnil, /* sp_lstchg, date when the password was last changed (in days since Jan 1, 1970) */ Qnil, /* sp_min, days that password must stay same */ Qnil, /* sp_max, days until password changes. */ Qnil, /* sp_warn, days before expiration where user is warned */ Qnil, /* sp_inact, days after password expiration that account becomes inactive */ INT2FIX(difftime(entry->pw_change, 0) / (24*60*60)), /* pw_change */ INT2FIX(difftime(entry->pw_expire, 0) / (24*60*60)), /* sp_expire */ Qnil, /* sp_flag */ rb_tainted_str_new2(entry->pw_class), /* sp_loginclass, user access class */ NULL); } static VALUE rb_shadow_getspent(VALUE self) { PWTYPE *entry; VALUE result; entry = getpwent(); if( entry == NULL ) return Qnil; result = convert_pw_struct( entry ); return result; } static VALUE rb_shadow_getspnam(VALUE self, VALUE name) { PWTYPE *entry; VALUE result; if( TYPE(name) != T_STRING ) rb_raise(rb_eException,"argument must be a string."); entry = getpwnam(StringValuePtr(name)); if( entry == NULL ) return Qnil; result = convert_pw_struct( entry ); return result; } void Init_shadow() { rb_sPasswdEntry = rb_struct_define("PasswdEntry", "sp_namp","sp_pwdp","sp_lstchg", "sp_min","sp_max","sp_warn", "sp_inact","pw_change", "sp_expire","sp_flag", "sp_loginclass", NULL); rb_sGroupEntry = rb_struct_define("GroupEntry", "sg_name","sg_passwd", "sg_adm","sg_mem",NULL); rb_mShadow = rb_define_module("Shadow"); rb_define_const( rb_mShadow, "IMPLEMENTATION", rb_str_new_cstr( "PWD" ) ); rb_eFileLock = rb_define_class_under(rb_mShadow,"FileLock",rb_eException); rb_mPasswd = rb_define_module_under(rb_mShadow,"Passwd"); rb_define_const(rb_mPasswd,"Entry",rb_sPasswdEntry); rb_mGroup = rb_define_module_under(rb_mShadow,"Group"); rb_define_const(rb_mGroup,"Entry",rb_sGroupEntry); rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0); rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0); rb_define_module_function(rb_mPasswd,"getspent",rb_shadow_getspent,0); rb_define_module_function(rb_mPasswd,"getspnam",rb_shadow_getspnam,1); rb_define_module_function(rb_mPasswd,"from_user_name",rb_shadow_getspnam,1); } ruby-shadow-2.5.0/ruby-shadow.gemspec000066400000000000000000000017551260503342600176040ustar00rootroot00000000000000# -*- encoding: utf-8 -*- Gem::Specification.new do |spec| spec.authors = ['Adam Palmblad', 'Eric Hankins', 'Ian Marlier', 'Jeff Blaine', 'Remi Broemeling', 'Takaaki Tateishi'] spec.description = 'This module provides access to shadow passwords on Linux, OSX, FreeBSD, OpenBSD, and Solaris' spec.email = ['adam.palmblad@teampages.com'] spec.extensions = ['extconf.rb'] spec.files = [] File.open('MANIFEST').each do |file| spec.files << file.chomp end spec.homepage = 'https://github.com/apalmblad/ruby-shadow' spec.name = 'ruby-shadow' spec.required_ruby_version = ['>= 1.8'] spec.summary = '*nix Shadow Password Module' spec.version = '2.5.0' spec.license = "Public Domain License" end ruby-shadow-2.5.0/shadow/000077500000000000000000000000001260503342600152505ustar00rootroot00000000000000ruby-shadow-2.5.0/shadow/depend000066400000000000000000000000231260503342600164250ustar00rootroot00000000000000shadow.o: shadow.c ruby-shadow-2.5.0/shadow/shadow.c000066400000000000000000000147271260503342600167140ustar00rootroot00000000000000/* * shadow.c * * Ruby extention module for using Linux shadow password. * * Copyright (C) 1998-1999 by Takaaki.Tateishi(ttate@jaist.ac.jp) * License: Free for any use with your own risk! */ #include #include "ruby.h" #ifdef HAVE_RUBY_IO_H #include "ruby/io.h" #else #include "rubyio.h" #endif #ifdef RUBY19 #define file_ptr(x) rb_io_stdio_file(x) #else #define file_ptr(x) (x)->f #endif #define NUM_FIELDS 10 static VALUE rb_mShadow; static VALUE rb_mPasswd; static VALUE rb_sPasswdEntry; static VALUE rb_mGroup; static VALUE rb_sGroupEntry; static VALUE rb_eFileLock; static VALUE convert_pw_struct( struct spwd *entry ) { return rb_struct_new(rb_sPasswdEntry, rb_tainted_str_new2(entry->sp_namp), rb_tainted_str_new2(entry->sp_pwdp), INT2FIX(entry->sp_lstchg), INT2FIX(entry->sp_min), INT2FIX(entry->sp_max), INT2FIX(entry->sp_warn), INT2FIX(entry->sp_inact), Qnil, /* used by BSD, pw_change, date when the password expires, in days since Jan 1, 1970 */ INT2FIX(entry->sp_expire), INT2FIX(entry->sp_flag), Qnil, NULL); }; static VALUE rb_shadow_setspent(VALUE self) { setspent(); return Qnil; }; static VALUE rb_shadow_endspent(VALUE self) { endspent(); return Qnil; }; #ifndef SOLARIS static VALUE rb_shadow_sgetspent(VALUE self, VALUE str) { struct spwd *entry; VALUE result; if( TYPE(str) != T_STRING ) rb_raise(rb_eException,"argument must be a string."); entry = sgetspent(StringValuePtr(str)); if( entry == NULL ) return Qnil; result = convert_pw_struct( entry ); free(entry); return result; }; #endif static VALUE rb_shadow_fgetspent(VALUE self, VALUE file) { struct spwd *entry; VALUE result; if( TYPE(file) != T_FILE ) rb_raise(rb_eTypeError,"argument must be a File."); entry = fgetspent( file_ptr( (RFILE(file)->fptr) ) ); if( entry == NULL ) return Qnil; result = convert_pw_struct( entry ); return result; }; static VALUE rb_shadow_getspent(VALUE self) { struct spwd *entry; VALUE result; entry = getspent(); if( entry == NULL ) return Qnil; return convert_pw_struct( entry ); }; static VALUE rb_shadow_getspnam(VALUE self, VALUE name) { struct spwd *entry; VALUE result; if( TYPE(name) != T_STRING ) rb_raise(rb_eException,"argument must be a string."); entry = getspnam(StringValuePtr(name)); if( entry == NULL ) return Qnil; return convert_pw_struct( entry ); }; static VALUE rb_shadow_putspent(VALUE self, VALUE entry, VALUE file) { struct spwd centry; FILE* cfile; VALUE val[NUM_FIELDS]; int i; int result; if( TYPE(file) != T_FILE ) rb_raise(rb_eTypeError,"argument must be a File."); /* for(i=0; iptr[i]; i//val[i] = rb_struct_aref( entry, i ); } */ cfile = file_ptr( RFILE(file)->fptr ); VALUE x = rb_ary_entry( entry, 0 ); centry.sp_namp = StringValuePtr( x ); x = rb_ary_entry( entry, 1 ); centry.sp_pwdp = StringValuePtr( x ); centry.sp_lstchg = FIX2INT( rb_ary_entry( entry, 2) ); centry.sp_min = FIX2INT( rb_ary_entry( entry, 3 ) ); centry.sp_max = FIX2INT( rb_ary_entry( entry, 4 ) ); centry.sp_warn = FIX2INT( rb_ary_entry( entry, 5 )); centry.sp_inact = FIX2INT( rb_ary_entry( entry, 6 ) ); // missing 7 I think is put in to deal with beign similar to BSD returns, for the value pw_change. centry.sp_expire = FIX2INT( rb_ary_entry( entry, 8 ) ); centry.sp_flag = FIX2INT( rb_ary_entry( entry, 9 ) ); result = putspent(¢ry,cfile); if( result == -1 ) rb_raise(rb_eStandardError,"can't change password"); return Qtrue; }; static VALUE rb_shadow_lckpwdf(VALUE self) { int result; result = lckpwdf(); if( result == -1 ) rb_raise(rb_eFileLock,"password file was locked"); else return Qtrue; }; static int in_lock; static VALUE rb_shadow_lock(VALUE self) { int result; if( rb_block_given_p() ){ result = lckpwdf(); if( result == -1 ){ rb_raise(rb_eFileLock,"password file was locked"); } else{ in_lock++; rb_yield(Qnil); in_lock--; ulckpwdf(); }; return Qtrue; } else{ return rb_shadow_lckpwdf(self); }; }; static VALUE rb_shadow_ulckpwdf(VALUE self) { if( in_lock ){ rb_raise(rb_eFileLock,"you call unlock method in lock iterator."); }; ulckpwdf(); return Qtrue; }; static VALUE rb_shadow_unlock(VALUE self) { return rb_shadow_ulckpwdf(self); }; static VALUE rb_shadow_lock_p(VALUE self) { int result; result = lckpwdf(); if( result == -1 ){ return Qtrue; } else{ ulckpwdf(); return Qfalse; }; }; void Init_shadow() { rb_sPasswdEntry = rb_struct_define("PasswdEntry", "sp_namp","sp_pwdp","sp_lstchg", "sp_min","sp_max","sp_warn", "sp_inact", "pw_change", "sp_expire","sp_flag", "sp_loginclass", NULL); rb_sGroupEntry = rb_struct_define("GroupEntry", "sg_name","sg_passwd", "sg_adm","sg_mem",NULL); rb_mShadow = rb_define_module("Shadow"); rb_define_const( rb_mShadow, "IMPLEMENTATION", rb_str_new_cstr( "SHADOW" ) ); rb_eFileLock = rb_define_class_under(rb_mShadow,"FileLock",rb_eException); rb_mPasswd = rb_define_module_under(rb_mShadow,"Passwd"); rb_define_const(rb_mPasswd,"Entry",rb_sPasswdEntry); rb_mGroup = rb_define_module_under(rb_mShadow,"Group"); rb_define_const(rb_mGroup,"Entry",rb_sGroupEntry); rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0); rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0); #ifndef SOLARIS rb_define_module_function(rb_mPasswd,"sgetspent",rb_shadow_sgetspent,1); #endif rb_define_module_function(rb_mPasswd,"fgetspent",rb_shadow_fgetspent,1); rb_define_module_function(rb_mPasswd,"getspent",rb_shadow_getspent,0); rb_define_module_function(rb_mPasswd,"getspnam",rb_shadow_getspnam,1); rb_define_module_function(rb_mPasswd,"from_user_name",rb_shadow_getspnam,1); rb_define_module_function(rb_mPasswd,"putspent",rb_shadow_putspent,2); rb_define_module_function(rb_mPasswd,"add_password_entry",rb_shadow_putspent,2); rb_define_module_function(rb_mPasswd,"lckpwdf",rb_shadow_lckpwdf,0); rb_define_module_function(rb_mPasswd,"lock",rb_shadow_lock,0); rb_define_module_function(rb_mPasswd,"ulckpwdf",rb_shadow_ulckpwdf,0); rb_define_module_function(rb_mPasswd,"unlock",rb_shadow_unlock,0); rb_define_module_function(rb_mPasswd,"lock?",rb_shadow_lock_p,0); }; ruby-shadow-2.5.0/test/000077500000000000000000000000001260503342600147425ustar00rootroot00000000000000ruby-shadow-2.5.0/test/basic_test.rb000066400000000000000000000037731260503342600174210ustar00rootroot00000000000000require 'test/unit' require 'rubygems' require 'shadow' require 'stringio' class RubyShadowTest < Test::Unit::TestCase STRUCT_METHODS = %w( sp_namp sp_pwdp sp_lstchg sp_min sp_max sp_warn sp_inact sp_expire sp_loginclass ) # --------------------------------------------------- test_smoke_test_getspent def test_smoke_test_getspent x = Shadow::Passwd.getspent assert( x, "ensure you have permissions to check this (sudo?)" ) check_struct( x ) end # ----------------------------------------------------- test_getspnam_for_user def test_getspnam_for_user user = `whoami`.strip x = Shadow::Passwd.getspnam( user ) assert( x, "ensure you have permissions to check this (sudo?)" ) check_struct( x ) end # ---------------------------------------- test_getspnam_for_non_existent_user def test_getspnam_for_non_existent_user assert_nil( Shadow::Passwd.getspnam( 'somebadusername' ) ) end # -------------------------------------------------------------- test_putspent def test_putspent omit_if( Shadow::IMPLEMENTATION != 'SHADOW' ) if respond_to?( :omit_if ) #result = StringIO.open( '', 'w' ) do |fh| File.open( 'test_password', 'w' ) do |fh| Shadow::Passwd.add_password_entry( sample_entry, fh ) end assert( File.read( 'test_password' ).match( sample_entry.first ) ) end # --------------------------------------------------------------- check_struct def check_struct( s ) STRUCT_METHODS.each do |m| s.send( m ) end end # ----------------------------------------------------------------- test_entry def sample_entry( &block ) return ['test_user', # sp_namp 'new_pass', # sp_pwdp 0, #sp_lastchg 0, #sp_min 0, #sp_max 0, #sp_warn 0, #sp_inact 0, #???? 0, #sp_expire 0 # sp_flag ] e = Shadow::Passwd::Entry.new e.sp_namp = 'test_user' e.sp_pwdp = 'password' yield e if block_given? return e end end