ruby-shadow-2.2.0/depend0000644000000000000000000000031612227312326013637 0ustar rootrootifneq (,$(findstring 1.9,$(ruby_version))) io_lib=$(hdrdir)/ruby/ruby/io.h hdr=$(hdrdir)/ruby/ruby.h else io_lib=$(hdrdir)/ruby/rubyio.h hdr=$(hdrdir)/ruby.h endif shadow.o: shadow.c $(hdr) $(io_lib) ruby-shadow-2.2.0/extconf.rb0000644000000000000000000000202212227312326014444 0ustar rootroot# -*- ruby -*- # extconf.rb # # Modified at: <1999/8/19 06:38:55 by ttate> # require 'mkmf' $CFLAGS = case RUBY_VERSION when /^1\.9/; '-DRUBY19' when /^2\./; '-DRUBY19' else; '' end #$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 create_makefile("shadow") else osx_ok = have_func( "endpwent" ) osx_ok &= have_func( "getpwent" ) osx_ok &= have_func( "getpwnam" ) osx_ok &= have_func( "getpwnam_r" ) osx_ok &= have_func( "getpwuid" ) osx_ok &= have_func( "setpassent" ) osx_ok &= have_func( "setpwent" ) if osx_ok raise "It looks like you're on OSX. There is a branch that might help here: https://github.com/apalmblad/ruby-shadow/tree/osx" end end ruby-shadow-2.2.0/HISTORY0000644000000000000000000000354012227312326013543 0ustar rootroot[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.2.0/LICENSE0000644000000000000000000000021612227312326013461 0ustar rootrootLicense: Free for any use with your own risk! OR The terms of the Public Domain License (http://creativecommons.org/licenses/publicdomain/) ruby-shadow-2.2.0/MANIFEST0000644000000000000000000000012112227312326013600 0ustar rootrootdepend extconf.rb HISTORY MANIFEST README README.euc ruby-shadow.gemspec shadow.cruby-shadow-2.2.0/README0000644000000000000000000000506412227312326013342 0ustar rootrootShadow 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 is the module which used when you access linux shadow password files. Recent versions work on both Linux and Solaris. 2. install ruby extconf.rb make (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 getspent getspnam(name) setspent endspent fgetspent(file) sgetspent(str) putspent(entry,file) lckpwdf,lock ulckpwdf,unlock lock? * Note: sgetspent is not available under Solaris and some other operating systems. In current versions, that method will be completely missing. 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. 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 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.2.0/README.euc0000644000000000000000000000402212227312326014106 0ustar rootrootShadow 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.2.0/ruby-shadow.gemspec0000644000000000000000000000172512227312326016273 0ustar rootroot# -*- 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 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.2.0' spec.license = "Public Domain License" end ruby-shadow-2.2.0/shadow.c0000644000000000000000000001506012227312326014110 0ustar rootroot/* * 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! * Modified at: <1999/8/19 06:48:18 by ttate> */ #include #include "ruby.h" #ifdef RUBY19 #include #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) { 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 = 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), INT2FIX(entry->sp_expire), INT2FIX(entry->sp_flag), NULL); 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 = 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), INT2FIX(entry->sp_expire), INT2FIX(entry->sp_flag), NULL); return result; }; static VALUE rb_shadow_getspent(VALUE self) { struct spwd *entry; VALUE result; entry = getspent(); if( entry == NULL ) return Qnil; result = 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), INT2FIX(entry->sp_expire), INT2FIX(entry->sp_flag), NULL); return result; }; 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; result = 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), INT2FIX(entry->sp_expire), INT2FIX(entry->sp_flag), NULL); return result; }; static VALUE rb_shadow_putspent(VALUE self, VALUE entry, VALUE file) { struct spwd centry; FILE* cfile; VALUE val[9]; int i; int result; for(i=0; i<=8; i++) val[i] = RSTRUCT_PTR( entry )[i]; //val[i] = RSTRUCT(entry)->ptr[i]; cfile = file_ptr( RFILE(file)->fptr ); centry.sp_namp = StringValuePtr(val[0]); centry.sp_pwdp = StringValuePtr(val[1]); centry.sp_lstchg = FIX2INT(val[2]); centry.sp_min = FIX2INT(val[3]); centry.sp_max = FIX2INT(val[4]); centry.sp_warn = FIX2INT(val[5]); centry.sp_inact = FIX2INT(val[6]); centry.sp_expire = FIX2INT(val[7]); centry.sp_flag = FIX2INT(val[8]); 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","sp_expire","sp_flag", NULL); rb_sGroupEntry = rb_struct_define("GroupEntry", "sg_name","sg_passwd", "sg_adm","sg_mem",NULL); rb_mShadow = rb_define_module("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,"putspent",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); };