ruby-shadow 2.2.0 → 2.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/HISTORY CHANGED
@@ -1,3 +1,17 @@
1
+ [2013/11/13]
2
+ * Version 2.3.1
3
+ - Caleb Land<caleb.land@gmail.com>
4
+ Remove sgetspent on implementations using pwd.h
5
+ [2013/11/13]
6
+ * Version 2.3.0
7
+ - Caleb Land<caleb.land@gmail.com>
8
+ Merge OS X work into main gem. Fix bugs with OS X implementation and tweak support for FreeBSD.
9
+ See https://github.com/caleb/ruby-shadow/commit/20d98b7d9e3bbbef0b737affd3245590096a316c
10
+ - Add license file to Manifest.
11
+ [2013/02/25]
12
+ - Adam Palmblad<apalmblad@gmail.com>
13
+ Fix compilation issues with ruby 2.
14
+
1
15
  [2012/04/17]
2
16
  * Version 2.1.4
3
17
  - MATSUU Takuto <matsuu@gentoo.org>
data/LICENSE ADDED
@@ -0,0 +1,5 @@
1
+ License: Free for any use with your own risk!
2
+
3
+ OR
4
+
5
+ The terms of the Public Domain License (http://creativecommons.org/licenses/publicdomain/)
data/MANIFEST CHANGED
@@ -1,8 +1,11 @@
1
- depend
2
1
  extconf.rb
3
2
  HISTORY
3
+ LICENSE
4
4
  MANIFEST
5
5
  README
6
6
  README.euc
7
7
  ruby-shadow.gemspec
8
- shadow.c
8
+ pwd/shadow.c
9
+ pwd/depend
10
+ shadow/shadow.c
11
+ shadow/depend
data/README CHANGED
@@ -5,16 +5,20 @@ Modified at: <1999/8/19 06:47:14 by ttate>
5
5
  License: See LICENSE
6
6
 
7
7
 
8
+
8
9
  1. What's this
9
10
 
10
- This is the module which used when you access linux shadow password files.
11
+ This module provides tools to read, and, on Linux, append, information related to password files.
12
+
13
+ Recent versions work on both Linux, Solaris, OS X and FreeBSD.
14
+ The functions found are translated to their equivalents in libshadow.
11
15
 
12
- Recent versions work on both Linux and Solaris.
16
+ Note
13
17
 
14
18
  2. install
15
19
 
16
20
  ruby extconf.rb
17
- make
21
+ make # use gmake on FreeBSD
18
22
  (make install)
19
23
 
20
24
  * Note:
@@ -22,20 +26,19 @@ make
22
26
  still present, but no promises about earlier versions of Ruby.
23
27
 
24
28
  3. Shadow::Passwd module's methods
25
-
26
- getspent
27
- getspnam(name)
28
- setspent
29
- endspent
30
- fgetspent(file)
31
- sgetspent(str)
32
- putspent(entry,file)
33
- lckpwdf,lock
34
- ulckpwdf,unlock
35
- lock?
36
-
37
- * Note: sgetspent is not available under Solaris and some other operating
38
- systems. In current versions, that method will be completely missing.
29
+ ____________________________________________________________
30
+ Method | Linux | Solaris | OS X | FreeBSD
31
+ ____________________________________________________________
32
+ getspent | * | * | * | *
33
+ getspnam(name) | * | * | * | *
34
+ setspent | * | * | * | *
35
+ endspent | * | * | * | *
36
+ fgetspent(file) | * | * | N | N
37
+ sgetspent(str) | * | N | N | N
38
+ putspent(entry,file) | * | * | N | N
39
+ lckpwdf,lock | * | * | N | N
40
+ ulckpwdf,unlock | * | * | N | N
41
+ lock? | * | * | N | N
39
42
 
40
43
 
41
44
  4. Structure
@@ -43,15 +46,16 @@ lock?
43
46
  Shadow::Passwd::Entry (Struct::PasswdEntry)
44
47
  sp_namp - pointer to null-terminated user name.
45
48
  sp_pwdp - pointer to null-terminated password.
46
- sp_lstchg - days since Jan 1, 1970 password was last
47
- changed.
49
+ sp_lstchg - days since Jan 1, 1970 password was last
50
+ changed.
48
51
  sp_min - days before which password may not be changed.
49
52
  sp_max - days after which password must be changed.
50
53
  sp_warn - days before password is to expire that user is
51
- warned of pending password expiration.
54
+ warned of pending password expiration.
52
55
  sp_inact - days after password expires that account is
53
56
  considered inactive and disabled.
54
57
  sp_expire - days since Jan 1, 1970 when account will be
58
+ disabled
55
59
 
56
60
 
57
61
  5. Description
data/extconf.rb CHANGED
@@ -5,6 +5,7 @@
5
5
  #
6
6
 
7
7
  require 'mkmf'
8
+ require 'rbconfig'
8
9
 
9
10
  $CFLAGS = case RUBY_VERSION
10
11
  when /^1\.9/; '-DRUBY19'
@@ -12,33 +13,54 @@ $CFLAGS = case RUBY_VERSION
12
13
  else; ''
13
14
  end
14
15
 
15
- #$LDFLAGS = "-lshadow"
16
+ implementation = case CONFIG['host_os']
17
+ when /linux/i; 'shadow'
18
+ when /sunos|solaris/i; 'shadow'
19
+ when /freebsd/i; 'pwd'
20
+ when /darwin/i; 'pwd'
21
+ else; nil
22
+ "This library works on OS X, FreeBSD, Solaris and Linux."
23
+ end
16
24
 
17
- if( ! (ok = have_library("shadow","getspent")) )
18
- $LDFLAGS = ""
19
- ok = have_func("getspent")
20
- end
25
+ ok = true
21
26
 
22
- ok &= have_func("fgetspent")
23
- ok &= have_func("setspent")
24
- ok &= have_func("endspent")
25
- ok &= have_func("lckpwdf")
26
- ok &= have_func("ulckpwdf")
27
+ case implementation
28
+ when 'shadow'
29
+ #$LDFLAGS = "-lshadow"
27
30
 
28
- if ok
29
- if !have_func("sgetspent")
30
- $CFLAGS += ' -DSOLARIS'
31
+ if( ! (ok &= have_library("shadow","getspent")) )
32
+ $LDFLAGS = ""
33
+ ok = have_func("getspent")
31
34
  end
32
- create_makefile("shadow")
33
- else
34
- osx_ok = have_func( "endpwent" )
35
- osx_ok &= have_func( "getpwent" )
36
- osx_ok &= have_func( "getpwnam" )
37
- osx_ok &= have_func( "getpwnam_r" )
38
- osx_ok &= have_func( "getpwuid" )
39
- osx_ok &= have_func( "setpassent" )
40
- osx_ok &= have_func( "setpwent" )
41
- if osx_ok
42
- raise "It looks like you're on OSX. There is a branch that might help here: https://github.com/apalmblad/ruby-shadow/tree/osx"
35
+
36
+ ok &= have_func("fgetspent")
37
+ ok &= have_func("setspent")
38
+ ok &= have_func("endspent")
39
+ ok &= have_func("lckpwdf")
40
+ ok &= have_func("ulckpwdf")
41
+
42
+ if ok
43
+ if !have_func("sgetspent")
44
+ $CFLAGS += ' -DSOLARIS'
45
+ end
43
46
  end
47
+ when 'pwd'
48
+ ok &= have_func("endpwent")
49
+ ok &= have_func("getpwent")
50
+ ok &= have_func("getpwnam")
51
+ ok &= have_func("getpwnam_r")
52
+ ok &= have_func("getpwuid")
53
+ ok &= have_func("setpassent")
54
+ ok &= have_func("setpwent")
55
+
56
+ have_header("uuid/uuid.h")
57
+ have_header("uuid.h")
58
+ else
59
+ ok = false
44
60
  end
61
+
62
+ if ok
63
+ create_makefile("shadow", implementation)
64
+ else
65
+ raise "You are missing some of the required functions from either shadow.h on Linux/Solaris, or pwd.h on FreeBSD/OS X."
66
+ end
File without changes
data/pwd/shadow.c ADDED
@@ -0,0 +1,125 @@
1
+ /*
2
+ * shadow.c
3
+ *
4
+ * Ruby extention module for using FreeBSD/OS X pwd.h.
5
+ *
6
+ * Copyright (C) 1998-1999 by Takaaki.Tateishi(ttate@jaist.ac.jp)
7
+ * License: Free for any use with your own risk!
8
+ */
9
+ #include <sys/types.h>
10
+ #include <pwd.h>
11
+ #include <time.h>
12
+ #ifdef HAVE_UUID_UUID_H
13
+ #include <uuid/uuid.h>
14
+ #elif HAVE_UUID_H
15
+ #include <uuid.h>
16
+ #endif
17
+ #define PWTYPE struct passwd
18
+
19
+ #include "ruby.h"
20
+ #ifdef RUBY19
21
+ #include <ruby/io.h>
22
+ #else
23
+ #include "rubyio.h"
24
+ #endif
25
+
26
+ #ifdef RUBY19
27
+ #define file_ptr(x) (x)->stdio_file
28
+ #else
29
+ #define file_ptr(x) (x)->f
30
+ #endif
31
+
32
+ static VALUE rb_mShadow;
33
+ static VALUE rb_mPasswd;
34
+ static VALUE rb_sPasswdEntry;
35
+ static VALUE rb_mGroup;
36
+ static VALUE rb_sGroupEntry;
37
+ static VALUE rb_eFileLock;
38
+
39
+
40
+ static VALUE
41
+ rb_shadow_setspent(VALUE self)
42
+ {
43
+ setpassent(1);
44
+ return Qnil;
45
+ }
46
+
47
+
48
+ static VALUE
49
+ rb_shadow_endspent(VALUE self)
50
+ {
51
+ endpwent();
52
+ return Qnil;
53
+ }
54
+
55
+ static VALUE convert_pw_struct( struct passwd *entry )
56
+ {
57
+ return rb_struct_new(rb_sPasswdEntry,
58
+ rb_tainted_str_new2(entry->pw_name),
59
+ rb_tainted_str_new2(entry->pw_passwd),
60
+ Qnil, /* date when the password was last changed (in days since Jan 1, 1970) */
61
+ Qnil, /* days that password must stay same */
62
+ Qnil, /* days until password changes. */
63
+ Qnil, /* days before expiration where user is warned */
64
+ Qnil, /* days after password expiration that account becomes inactive */
65
+ INT2FIX(difftime(entry->pw_change, 0) / (24*60*60)),
66
+ INT2FIX(difftime(entry->pw_expire, 0) / (24*60*60)),
67
+ Qnil, /* sp_flag */
68
+ NULL);
69
+ }
70
+
71
+ static VALUE
72
+ rb_shadow_getspent(VALUE self)
73
+ {
74
+ PWTYPE *entry;
75
+ VALUE result;
76
+ entry = getpwent();
77
+
78
+ if( entry == NULL )
79
+ return Qnil;
80
+
81
+ result = convert_pw_struct( entry );
82
+ return result;
83
+ }
84
+
85
+ static VALUE
86
+ rb_shadow_getspnam(VALUE self, VALUE name)
87
+ {
88
+ PWTYPE *entry;
89
+ VALUE result;
90
+
91
+ if( TYPE(name) != T_STRING )
92
+ rb_raise(rb_eException,"argument must be a string.");
93
+ entry = getpwnam(StringValuePtr(name));
94
+
95
+ if( entry == NULL )
96
+ return Qnil;
97
+
98
+ result = convert_pw_struct( entry );
99
+ return result;
100
+ }
101
+
102
+ void
103
+ Init_shadow()
104
+ {
105
+ rb_sPasswdEntry = rb_struct_define("PasswdEntry",
106
+ "sp_namp","sp_pwdp","sp_lstchg",
107
+ "sp_min","sp_max","sp_warn",
108
+ "sp_inact","pw_change",
109
+ "sp_expire","sp_flag", NULL);
110
+ rb_sGroupEntry = rb_struct_define("GroupEntry",
111
+ "sg_name","sg_passwd",
112
+ "sg_adm","sg_mem",NULL);
113
+
114
+ rb_mShadow = rb_define_module("Shadow");
115
+ rb_eFileLock = rb_define_class_under(rb_mShadow,"FileLock",rb_eException);
116
+ rb_mPasswd = rb_define_module_under(rb_mShadow,"Passwd");
117
+ rb_define_const(rb_mPasswd,"Entry",rb_sPasswdEntry);
118
+ rb_mGroup = rb_define_module_under(rb_mShadow,"Group");
119
+ rb_define_const(rb_mGroup,"Entry",rb_sGroupEntry);
120
+
121
+ rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0);
122
+ rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0);
123
+ rb_define_module_function(rb_mPasswd,"getspent",rb_shadow_getspent,0);
124
+ rb_define_module_function(rb_mPasswd,"getspnam",rb_shadow_getspnam,1);
125
+ }
data/ruby-shadow.gemspec CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  'Remi Broemeling',
9
9
  'Takaaki Tateishi']
10
10
 
11
- spec.description = 'This module provides access to shadow passwords on Linux and Solaris'
11
+ spec.description = 'This module provides access to shadow passwords on Linux, OSX, FreeBSD, and Solaris'
12
12
  spec.email = ['adam.palmblad@teampages.com']
13
13
  spec.extensions = ['extconf.rb']
14
14
  spec.files = []
@@ -19,6 +19,6 @@ Gem::Specification.new do |spec|
19
19
  spec.name = 'ruby-shadow'
20
20
  spec.required_ruby_version = ['>= 1.8']
21
21
  spec.summary = '*nix Shadow Password Module'
22
- spec.version = '2.2.0'
22
+ spec.version = '2.3.1'
23
23
  spec.license = "Public Domain License"
24
24
  end
data/shadow/depend ADDED
@@ -0,0 +1,9 @@
1
+ ifneq (,$(findstring 1.9,$(ruby_version)))
2
+ io_lib=$(hdrdir)/ruby/ruby/io.h
3
+ hdr=$(hdrdir)/ruby/ruby.h
4
+ else
5
+ io_lib=$(hdrdir)/ruby/rubyio.h
6
+ hdr=$(hdrdir)/ruby.h
7
+ endif
8
+
9
+ shadow.o: shadow.c $(hdr) $(io_lib)
@@ -5,7 +5,6 @@
5
5
  *
6
6
  * Copyright (C) 1998-1999 by Takaaki.Tateishi(ttate@jaist.ac.jp)
7
7
  * License: Free for any use with your own risk!
8
- * Modified at: <1999/8/19 06:48:18 by ttate>
9
8
  */
10
9
 
11
10
  #include <shadow.h>
@@ -17,11 +16,13 @@
17
16
  #endif
18
17
 
19
18
  #ifdef RUBY19
20
- #define file_ptr(x) (x)->stdio_file
19
+ #define file_ptr(x) rb_io_stdio_file(x)
21
20
  #else
22
21
  #define file_ptr(x) (x)->f
23
22
  #endif
24
23
 
24
+ #define NUM_FIELDS 10
25
+
25
26
  static VALUE rb_mShadow;
26
27
  static VALUE rb_mPasswd;
27
28
  static VALUE rb_sPasswdEntry;
@@ -69,6 +70,7 @@ rb_shadow_sgetspent(VALUE self, VALUE str)
69
70
  INT2FIX(entry->sp_max),
70
71
  INT2FIX(entry->sp_warn),
71
72
  INT2FIX(entry->sp_inact),
73
+ Qnil, /* used by BSD, pw_change, date when the password expires, in days since Jan 1, 1970 */
72
74
  INT2FIX(entry->sp_expire),
73
75
  INT2FIX(entry->sp_flag),
74
76
  NULL);
@@ -85,7 +87,6 @@ rb_shadow_fgetspent(VALUE self, VALUE file)
85
87
 
86
88
  if( TYPE(file) != T_FILE )
87
89
  rb_raise(rb_eTypeError,"argument must be a File.");
88
-
89
90
  entry = fgetspent( file_ptr( (RFILE(file)->fptr) ) );
90
91
 
91
92
  if( entry == NULL )
@@ -99,6 +100,7 @@ rb_shadow_fgetspent(VALUE self, VALUE file)
99
100
  INT2FIX(entry->sp_max),
100
101
  INT2FIX(entry->sp_warn),
101
102
  INT2FIX(entry->sp_inact),
103
+ Qnil, /* used by BSD, pw_change, date when the password expires, in days since Jan 1, 1970 */
102
104
  INT2FIX(entry->sp_expire),
103
105
  INT2FIX(entry->sp_flag),
104
106
  NULL);
@@ -124,6 +126,7 @@ rb_shadow_getspent(VALUE self)
124
126
  INT2FIX(entry->sp_max),
125
127
  INT2FIX(entry->sp_warn),
126
128
  INT2FIX(entry->sp_inact),
129
+ Qnil, /* used by BSD, pw_change, date when the password expires, in days since Jan 1, 1970 */
127
130
  INT2FIX(entry->sp_expire),
128
131
  INT2FIX(entry->sp_flag),
129
132
  NULL);
@@ -152,6 +155,7 @@ rb_shadow_getspnam(VALUE self, VALUE name)
152
155
  INT2FIX(entry->sp_max),
153
156
  INT2FIX(entry->sp_warn),
154
157
  INT2FIX(entry->sp_inact),
158
+ Qnil, /* used by BSD, pw_change, date when the password expires, in days since Jan 1, 1970 */
155
159
  INT2FIX(entry->sp_expire),
156
160
  INT2FIX(entry->sp_flag),
157
161
  NULL);
@@ -164,14 +168,18 @@ rb_shadow_putspent(VALUE self, VALUE entry, VALUE file)
164
168
  {
165
169
  struct spwd centry;
166
170
  FILE* cfile;
167
- VALUE val[9];
171
+ VALUE val[NUM_FIELDS];
168
172
  int i;
169
173
  int result;
170
174
 
171
- for(i=0; i<=8; i++)
175
+ if( TYPE(file) != T_FILE )
176
+ rb_raise(rb_eTypeError,"argument must be a File.");
177
+
178
+ for(i=0; i<NUM_FIELDS; i++)
172
179
  val[i] = RSTRUCT_PTR( entry )[i]; //val[i] = RSTRUCT(entry)->ptr[i];
173
180
  cfile = file_ptr( RFILE(file)->fptr );
174
181
 
182
+
175
183
  centry.sp_namp = StringValuePtr(val[0]);
176
184
  centry.sp_pwdp = StringValuePtr(val[1]);
177
185
  centry.sp_lstchg = FIX2INT(val[2]);
@@ -179,8 +187,8 @@ rb_shadow_putspent(VALUE self, VALUE entry, VALUE file)
179
187
  centry.sp_max = FIX2INT(val[4]);
180
188
  centry.sp_warn = FIX2INT(val[5]);
181
189
  centry.sp_inact = FIX2INT(val[6]);
182
- centry.sp_expire = FIX2INT(val[7]);
183
- centry.sp_flag = FIX2INT(val[8]);
190
+ centry.sp_expire = FIX2INT(val[8]);
191
+ centry.sp_flag = FIX2INT(val[9]);
184
192
 
185
193
  result = putspent(&centry,cfile);
186
194
 
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-shadow
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.2.0
4
+ version: 2.3.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Adam Palmblad
@@ -13,9 +14,10 @@ authors:
13
14
  autorequire:
14
15
  bindir: bin
15
16
  cert_chain: []
16
- date: 2013-02-25 00:00:00.000000000 Z
17
+ date: 2013-11-13 00:00:00.000000000 Z
17
18
  dependencies: []
18
- description: This module provides access to shadow passwords on Linux and Solaris
19
+ description: This module provides access to shadow passwords on Linux, OSX, FreeBSD,
20
+ and Solaris
19
21
  email:
20
22
  - adam.palmblad@teampages.com
21
23
  executables: []
@@ -24,35 +26,40 @@ extensions:
24
26
  extra_rdoc_files: []
25
27
  files:
26
28
  - extconf.rb
27
- - depend
28
29
  - HISTORY
30
+ - LICENSE
29
31
  - MANIFEST
30
32
  - README
31
33
  - README.euc
32
34
  - ruby-shadow.gemspec
33
- - shadow.c
35
+ - pwd/shadow.c
36
+ - pwd/depend
37
+ - shadow/shadow.c
38
+ - shadow/depend
34
39
  homepage: https://github.com/apalmblad/ruby-shadow
35
40
  licenses:
36
41
  - Public Domain License
37
- metadata: {}
38
42
  post_install_message:
39
43
  rdoc_options: []
40
44
  require_paths:
41
45
  - lib
42
46
  required_ruby_version: !ruby/object:Gem::Requirement
47
+ none: false
43
48
  requirements:
44
- - - '>='
49
+ - - ! '>='
45
50
  - !ruby/object:Gem::Version
46
51
  version: '1.8'
47
52
  required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
48
54
  requirements:
49
- - - '>='
55
+ - - ! '>='
50
56
  - !ruby/object:Gem::Version
51
57
  version: '0'
52
58
  requirements: []
53
59
  rubyforge_project:
54
- rubygems_version: 2.0.0
60
+ rubygems_version: 1.8.25
55
61
  signing_key:
56
- specification_version: 4
57
- summary: '*nix Shadow Password Module'
62
+ specification_version: 3
63
+ summary: ! '*nix Shadow Password Module'
58
64
  test_files: []
65
+ has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: e6a1653f5597ff8d3d7766345624bac5a391bf0c
4
- data.tar.gz: c0b3f349395f0a66f86aef57580044cd47cf7e3f
5
- SHA512:
6
- metadata.gz: c5e7fb7ad3d9f82d84be27c0e21fb476b6b530e15b2d0fe49e9d88cd89e3c848cc45512db1eae38606ace6a8efa33e9897346196bcf3d6b90541ac10282bc964
7
- data.tar.gz: adfff1ae1f2cfc6096baa0aab23cb467fca95561020c610bb417a8c1fe5c09229893142383e2131f2a929f2c1bea4c7d575b42f89c97c7f47e9b4fd6332b67cd