ruby-shadow-2.4.1/0000755000004100000410000000000012454616544014025 5ustar www-datawww-dataruby-shadow-2.4.1/ruby-shadow.gemspec0000644000004100000410000000175512454616544017646 0ustar www-datawww-data# -*- 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.4.1' spec.license = "Public Domain License" end ruby-shadow-2.4.1/README.euc0000644000004100000410000000402212454616544015456 0ustar www-datawww-dataShadow 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.4.1/extconf.rb0000644000004100000410000000305612454616544016024 0ustar www-datawww-data# -*- 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.4.1/shadow/0000755000004100000410000000000012454616544015312 5ustar www-datawww-dataruby-shadow-2.4.1/shadow/shadow.c0000644000004100000410000001356712454616544016757 0ustar www-datawww-data/* * 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]; 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[8]); centry.sp_flag = FIX2INT(val[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_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); }; ruby-shadow-2.4.1/shadow/depend0000644000004100000410000000002312454616544016467 0ustar www-datawww-datashadow.o: shadow.c ruby-shadow-2.4.1/README0000644000004100000410000000644412454616544014715 0ustar www-datawww-dataShadow 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) | * | * | * | * setspent | * | * | * | * endspent | * | * | * | * fgetspent(file) | * | * | N | N sgetspent(str) | * | N | N | N putspent(entry,file) | * | * | N | N lckpwdf,lock | * | * | N | N ulckpwdf,unlock | * | * | N | N lock? | * | * | N | N 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/shadow-maint/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.4.1/metadata.yml0000644000004100000410000000236312454616544016334 0ustar www-datawww-data--- !ruby/object:Gem::Specification name: ruby-shadow version: !ruby/object:Gem::Version version: 2.4.1 platform: ruby authors: - Adam Palmblad - Eric Hankins - Ian Marlier - Jeff Blaine - Remi Broemeling - Takaaki Tateishi autorequire: bindir: bin cert_chain: [] date: 2014-12-02 00:00:00.000000000 Z dependencies: [] description: This module provides access to shadow passwords on Linux, OSX, FreeBSD, OpenBSD, and Solaris email: - adam.palmblad@teampages.com executables: [] extensions: - extconf.rb extra_rdoc_files: [] files: - HISTORY - LICENSE - MANIFEST - README - README.euc - extconf.rb - pwd/depend - pwd/shadow.c - ruby-shadow.gemspec - shadow/depend - shadow/shadow.c homepage: https://github.com/apalmblad/ruby-shadow licenses: - Public Domain License metadata: {} post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '1.8' required_rubygems_version: !ruby/object:Gem::Requirement requirements: - - ">=" - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 2.4.2 signing_key: specification_version: 4 summary: "*nix Shadow Password Module" test_files: [] ruby-shadow-2.4.1/MANIFEST0000644000004100000410000000020012454616544015146 0ustar www-datawww-dataextconf.rb HISTORY LICENSE MANIFEST README README.euc ruby-shadow.gemspec pwd/shadow.c pwd/depend shadow/shadow.c shadow/depend ruby-shadow-2.4.1/HISTORY0000644000004100000410000000563612454616544015123 0ustar www-datawww-data[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.4.1/LICENSE0000644000004100000410000000021612454616544015031 0ustar www-datawww-dataLicense: Free for any use with your own risk! OR The terms of the Public Domain License (http://creativecommons.org/licenses/publicdomain/) ruby-shadow-2.4.1/pwd/0000755000004100000410000000000012454616544014617 5ustar www-datawww-dataruby-shadow-2.4.1/pwd/shadow.c0000644000004100000410000000700412454616544016251 0ustar www-datawww-data/* * 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_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); } ruby-shadow-2.4.1/pwd/depend0000644000004100000410000000002312454616544015774 0ustar www-datawww-datashadow.o: shadow.c