libshadow 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +10 -0
- data/README.rdoc +48 -0
- data/Rakefile +6 -0
- data/ext/shadow/extconf.rb +26 -0
- data/ext/shadow/shadow.c +281 -0
- data/lib/libshadow.rb +5 -0
- data/libshadow.gemspec +21 -0
- metadata +74 -0
data/.gitignore
ADDED
data/README.rdoc
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
= libshadow
|
2
|
+
|
3
|
+
* http://github.com/#{github_username}/#{project_name}
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
FIX (describe your package)
|
8
|
+
|
9
|
+
== FEATURES/PROBLEMS:
|
10
|
+
|
11
|
+
* FIX (list of features or problems)
|
12
|
+
|
13
|
+
== SYNOPSIS:
|
14
|
+
|
15
|
+
FIX (code sample of usage)
|
16
|
+
|
17
|
+
== REQUIREMENTS:
|
18
|
+
|
19
|
+
* FIX (list of requirements)
|
20
|
+
|
21
|
+
== INSTALL:
|
22
|
+
|
23
|
+
* FIX (sudo gem install, anything else)
|
24
|
+
|
25
|
+
== LICENSE:
|
26
|
+
|
27
|
+
(The MIT License)
|
28
|
+
|
29
|
+
Copyright (c) 2010 FIXME full name
|
30
|
+
|
31
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
32
|
+
a copy of this software and associated documentation files (the
|
33
|
+
'Software'), to deal in the Software without restriction, including
|
34
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
35
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
36
|
+
permit persons to whom the Software is furnished to do so, subject to
|
37
|
+
the following conditions:
|
38
|
+
|
39
|
+
The above copyright notice and this permission notice shall be
|
40
|
+
included in all copies or substantial portions of the Software.
|
41
|
+
|
42
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
43
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
44
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
45
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
46
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
47
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
48
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# extconf.rb
|
3
|
+
#
|
4
|
+
# Modified at: <1999/8/19 06:38:55 by ttate>
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'mkmf'
|
8
|
+
|
9
|
+
$CFLAGS = ""
|
10
|
+
$LDFLAGS = "-lshadow"
|
11
|
+
|
12
|
+
if( ! (ok = have_library("shadow","getspent")) )
|
13
|
+
$LDFLAGS = ""
|
14
|
+
ok = have_func("getspent")
|
15
|
+
end
|
16
|
+
|
17
|
+
ok &= have_func("sgetspent")
|
18
|
+
ok &= have_func("fgetspent")
|
19
|
+
ok &= have_func("setspent")
|
20
|
+
ok &= have_func("endspent")
|
21
|
+
ok &= have_func("lckpwdf")
|
22
|
+
ok &= have_func("ulckpwdf")
|
23
|
+
|
24
|
+
if ok
|
25
|
+
create_makefile("shadow")
|
26
|
+
end
|
data/ext/shadow/shadow.c
ADDED
@@ -0,0 +1,281 @@
|
|
1
|
+
/*
|
2
|
+
* shadow.c
|
3
|
+
*
|
4
|
+
* Ruby extention module for using Linux shadow password.
|
5
|
+
*
|
6
|
+
* Copyright (C) 1998-1999 by Takaaki.Tateishi(ttate@jaist.ac.jp)
|
7
|
+
* License: Free for any use with your own risk!
|
8
|
+
* Modified at: <1999/8/19 06:48:18 by ttate>
|
9
|
+
*/
|
10
|
+
|
11
|
+
#include <shadow.h>
|
12
|
+
#include "ruby.h"
|
13
|
+
#include "rubyio.h"
|
14
|
+
|
15
|
+
static VALUE rb_mShadow;
|
16
|
+
static VALUE rb_mPasswd;
|
17
|
+
static VALUE rb_sPasswdEntry;
|
18
|
+
static VALUE rb_mGroup;
|
19
|
+
static VALUE rb_sGroupEntry;
|
20
|
+
static VALUE rb_eFileLock;
|
21
|
+
|
22
|
+
|
23
|
+
static VALUE
|
24
|
+
rb_shadow_setspent(VALUE self)
|
25
|
+
{
|
26
|
+
setspent();
|
27
|
+
return Qnil;
|
28
|
+
};
|
29
|
+
|
30
|
+
|
31
|
+
static VALUE
|
32
|
+
rb_shadow_endspent(VALUE self)
|
33
|
+
{
|
34
|
+
endspent();
|
35
|
+
return Qnil;
|
36
|
+
};
|
37
|
+
|
38
|
+
|
39
|
+
static VALUE
|
40
|
+
rb_shadow_sgetspent(VALUE self, VALUE str)
|
41
|
+
{
|
42
|
+
struct spwd *entry;
|
43
|
+
VALUE result;
|
44
|
+
|
45
|
+
if( TYPE(str) != T_STRING )
|
46
|
+
rb_raise(rb_eException,"argument must be a string.");
|
47
|
+
|
48
|
+
entry = sgetspent(STR2CSTR(str));
|
49
|
+
|
50
|
+
if( entry == NULL )
|
51
|
+
return Qnil;
|
52
|
+
|
53
|
+
result = rb_struct_new(rb_sPasswdEntry,
|
54
|
+
rb_tainted_str_new2(entry->sp_namp),
|
55
|
+
rb_tainted_str_new2(entry->sp_pwdp),
|
56
|
+
INT2FIX(entry->sp_lstchg),
|
57
|
+
INT2FIX(entry->sp_min),
|
58
|
+
INT2FIX(entry->sp_max),
|
59
|
+
INT2FIX(entry->sp_warn),
|
60
|
+
INT2FIX(entry->sp_inact),
|
61
|
+
INT2FIX(entry->sp_expire),
|
62
|
+
INT2FIX(entry->sp_flag),
|
63
|
+
0);
|
64
|
+
free(entry);
|
65
|
+
return result;
|
66
|
+
};
|
67
|
+
|
68
|
+
static VALUE
|
69
|
+
rb_shadow_fgetspent(VALUE self, VALUE file)
|
70
|
+
{
|
71
|
+
struct spwd *entry;
|
72
|
+
VALUE result;
|
73
|
+
|
74
|
+
if( TYPE(file) != T_FILE )
|
75
|
+
rb_raise(rb_eTypeError,"argument must be a File.");
|
76
|
+
|
77
|
+
entry = fgetspent((RFILE(file)->fptr)->f);
|
78
|
+
|
79
|
+
if( entry == NULL )
|
80
|
+
return Qnil;
|
81
|
+
|
82
|
+
result = rb_struct_new(rb_sPasswdEntry,
|
83
|
+
rb_tainted_str_new2(entry->sp_namp),
|
84
|
+
rb_tainted_str_new2(entry->sp_pwdp),
|
85
|
+
INT2FIX(entry->sp_lstchg),
|
86
|
+
INT2FIX(entry->sp_min),
|
87
|
+
INT2FIX(entry->sp_max),
|
88
|
+
INT2FIX(entry->sp_warn),
|
89
|
+
INT2FIX(entry->sp_inact),
|
90
|
+
INT2FIX(entry->sp_expire),
|
91
|
+
INT2FIX(entry->sp_flag),
|
92
|
+
0);
|
93
|
+
return result;
|
94
|
+
};
|
95
|
+
|
96
|
+
static VALUE
|
97
|
+
rb_shadow_getspent(VALUE self)
|
98
|
+
{
|
99
|
+
struct spwd *entry;
|
100
|
+
VALUE result;
|
101
|
+
|
102
|
+
entry = getspent();
|
103
|
+
|
104
|
+
if( entry == NULL )
|
105
|
+
return Qnil;
|
106
|
+
|
107
|
+
result = rb_struct_new(rb_sPasswdEntry,
|
108
|
+
rb_tainted_str_new2(entry->sp_namp),
|
109
|
+
rb_tainted_str_new2(entry->sp_pwdp),
|
110
|
+
INT2FIX(entry->sp_lstchg),
|
111
|
+
INT2FIX(entry->sp_min),
|
112
|
+
INT2FIX(entry->sp_max),
|
113
|
+
INT2FIX(entry->sp_warn),
|
114
|
+
INT2FIX(entry->sp_inact),
|
115
|
+
INT2FIX(entry->sp_expire),
|
116
|
+
INT2FIX(entry->sp_flag),
|
117
|
+
0);
|
118
|
+
return result;
|
119
|
+
};
|
120
|
+
|
121
|
+
static VALUE
|
122
|
+
rb_shadow_getspnam(VALUE self, VALUE name)
|
123
|
+
{
|
124
|
+
struct spwd *entry;
|
125
|
+
VALUE result;
|
126
|
+
|
127
|
+
if( TYPE(name) != T_STRING )
|
128
|
+
rb_raise(rb_eException,"argument must be a string.");
|
129
|
+
|
130
|
+
entry = getspnam(STR2CSTR(name));
|
131
|
+
|
132
|
+
if( entry == NULL )
|
133
|
+
return Qnil;
|
134
|
+
|
135
|
+
result = rb_struct_new(rb_sPasswdEntry,
|
136
|
+
rb_tainted_str_new2(entry->sp_namp),
|
137
|
+
rb_tainted_str_new2(entry->sp_pwdp),
|
138
|
+
INT2FIX(entry->sp_lstchg),
|
139
|
+
INT2FIX(entry->sp_min),
|
140
|
+
INT2FIX(entry->sp_max),
|
141
|
+
INT2FIX(entry->sp_warn),
|
142
|
+
INT2FIX(entry->sp_inact),
|
143
|
+
INT2FIX(entry->sp_expire),
|
144
|
+
INT2FIX(entry->sp_flag),
|
145
|
+
0);
|
146
|
+
return result;
|
147
|
+
};
|
148
|
+
|
149
|
+
|
150
|
+
static VALUE
|
151
|
+
rb_shadow_putspent(VALUE self, VALUE entry, VALUE file)
|
152
|
+
{
|
153
|
+
struct spwd centry;
|
154
|
+
FILE* cfile;
|
155
|
+
VALUE val[9];
|
156
|
+
int i;
|
157
|
+
int result;
|
158
|
+
|
159
|
+
for(i=0; i<=8; i++)
|
160
|
+
val[i] = RSTRUCT(entry)->ptr[i];
|
161
|
+
cfile = RFILE(file)->fptr->f;
|
162
|
+
|
163
|
+
centry.sp_namp = STR2CSTR(val[0]);
|
164
|
+
centry.sp_pwdp = STR2CSTR(val[1]);
|
165
|
+
centry.sp_lstchg = FIX2INT(val[2]);
|
166
|
+
centry.sp_min = FIX2INT(val[3]);
|
167
|
+
centry.sp_max = FIX2INT(val[4]);
|
168
|
+
centry.sp_warn = FIX2INT(val[5]);
|
169
|
+
centry.sp_inact = FIX2INT(val[6]);
|
170
|
+
centry.sp_expire = FIX2INT(val[7]);
|
171
|
+
centry.sp_flag = FIX2INT(val[8]);
|
172
|
+
|
173
|
+
result = putspent(¢ry,cfile);
|
174
|
+
|
175
|
+
if( result == -1 )
|
176
|
+
rb_raise(rb_eStandardError,"can't change password");
|
177
|
+
|
178
|
+
return Qtrue;
|
179
|
+
};
|
180
|
+
|
181
|
+
|
182
|
+
static VALUE
|
183
|
+
rb_shadow_lckpwdf(VALUE self)
|
184
|
+
{
|
185
|
+
int result;
|
186
|
+
result = lckpwdf();
|
187
|
+
if( result == -1 )
|
188
|
+
rb_raise(rb_eFileLock,"password file was locked");
|
189
|
+
else
|
190
|
+
return Qtrue;
|
191
|
+
};
|
192
|
+
|
193
|
+
static int in_lock;
|
194
|
+
|
195
|
+
static VALUE
|
196
|
+
rb_shadow_lock(VALUE self)
|
197
|
+
{
|
198
|
+
int result;
|
199
|
+
|
200
|
+
if( rb_iterator_p() ){
|
201
|
+
result = lckpwdf();
|
202
|
+
if( result == -1 ){
|
203
|
+
rb_raise(rb_eFileLock,"password file was locked");
|
204
|
+
}
|
205
|
+
else{
|
206
|
+
in_lock++;
|
207
|
+
rb_yield(Qnil);
|
208
|
+
in_lock--;
|
209
|
+
ulckpwdf();
|
210
|
+
};
|
211
|
+
return Qtrue;
|
212
|
+
}
|
213
|
+
else{
|
214
|
+
return rb_shadow_lckpwdf(self);
|
215
|
+
};
|
216
|
+
};
|
217
|
+
|
218
|
+
|
219
|
+
static VALUE
|
220
|
+
rb_shadow_ulckpwdf(VALUE self)
|
221
|
+
{
|
222
|
+
if( in_lock ){
|
223
|
+
rb_raise(rb_eFileLock,"you call unlock method in lock iterator.");
|
224
|
+
};
|
225
|
+
ulckpwdf();
|
226
|
+
return Qtrue;
|
227
|
+
};
|
228
|
+
|
229
|
+
static VALUE
|
230
|
+
rb_shadow_unlock(VALUE self)
|
231
|
+
{
|
232
|
+
return rb_shadow_ulckpwdf(self);
|
233
|
+
};
|
234
|
+
|
235
|
+
static VALUE
|
236
|
+
rb_shadow_lock_p(VALUE self)
|
237
|
+
{
|
238
|
+
int result;
|
239
|
+
|
240
|
+
result = lckpwdf();
|
241
|
+
if( result == -1 ){
|
242
|
+
return Qtrue;
|
243
|
+
}
|
244
|
+
else{
|
245
|
+
ulckpwdf();
|
246
|
+
return Qfalse;
|
247
|
+
};
|
248
|
+
};
|
249
|
+
|
250
|
+
|
251
|
+
void
|
252
|
+
Init_shadow()
|
253
|
+
{
|
254
|
+
rb_sPasswdEntry = rb_struct_define("PasswdEntry",
|
255
|
+
"sp_namp","sp_pwdp","sp_lstchg",
|
256
|
+
"sp_min","sp_max","sp_warn",
|
257
|
+
"sp_inact","sp_expire","sp_flag",0);
|
258
|
+
rb_sGroupEntry = rb_struct_define("GroupEntry",
|
259
|
+
"sg_name","sg_passwd",
|
260
|
+
"sg_adm","sg_mem",0);
|
261
|
+
|
262
|
+
rb_mShadow = rb_define_module("Shadow");
|
263
|
+
rb_eFileLock = rb_define_class_under(rb_mShadow,"FileLock",rb_eException);
|
264
|
+
rb_mPasswd = rb_define_module_under(rb_mShadow,"Passwd");
|
265
|
+
rb_define_const(rb_mPasswd,"Entry",rb_sPasswdEntry);
|
266
|
+
rb_mGroup = rb_define_module_under(rb_mShadow,"Group");
|
267
|
+
rb_define_const(rb_mGroup,"Entry",rb_sGroupEntry);
|
268
|
+
|
269
|
+
rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0);
|
270
|
+
rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0);
|
271
|
+
rb_define_module_function(rb_mPasswd,"sgetspent",rb_shadow_sgetspent,1);
|
272
|
+
rb_define_module_function(rb_mPasswd,"fgetspent",rb_shadow_fgetspent,1);
|
273
|
+
rb_define_module_function(rb_mPasswd,"getspent",rb_shadow_getspent,0);
|
274
|
+
rb_define_module_function(rb_mPasswd,"getspnam",rb_shadow_getspnam,1);
|
275
|
+
rb_define_module_function(rb_mPasswd,"putspent",rb_shadow_putspent,2);
|
276
|
+
rb_define_module_function(rb_mPasswd,"lckpwdf",rb_shadow_lckpwdf,0);
|
277
|
+
rb_define_module_function(rb_mPasswd,"lock",rb_shadow_lock,0);
|
278
|
+
rb_define_module_function(rb_mPasswd,"ulckpwdf",rb_shadow_ulckpwdf,0);
|
279
|
+
rb_define_module_function(rb_mPasswd,"unlock",rb_shadow_unlock,0);
|
280
|
+
rb_define_module_function(rb_mPasswd,"lock?",rb_shadow_lock_p,0);
|
281
|
+
};
|
data/lib/libshadow.rb
ADDED
data/libshadow.gemspec
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
$LOAD_PATH << File.join(File.dirname(__FILE__), "lib")
|
2
|
+
require "libshadow"
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = %q{libshadow}
|
6
|
+
s.summary = %q{shadow.h}
|
7
|
+
s.description = %q{Ruby C Extension for shadow access}
|
8
|
+
s.homepage = %q{http://github.com/railsmachine/libshadow}
|
9
|
+
s.version = Shadow::VERSION
|
10
|
+
s.authors = ["Jesse Newland", "Lee Jones"]
|
11
|
+
s.email = %q{ops@railsmachine.com}
|
12
|
+
|
13
|
+
s.rubygems_version = %q{1.3.7}
|
14
|
+
s.date = %q{2010-11-03}
|
15
|
+
|
16
|
+
s.require_paths = ["lib"]
|
17
|
+
s.extensions = ["ext/shadow/extconf.rb"]
|
18
|
+
s.files = %x{git ls-files}.split("\n").reject {|file| file =~ /^(features|cucumber)/ }
|
19
|
+
s.test_files = %x{git ls-files}.split("\n").select {|file| file =~ /^(features|cucumber)/ }
|
20
|
+
end
|
21
|
+
|
metadata
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: libshadow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 2
|
10
|
+
version: 0.0.2
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jesse Newland
|
14
|
+
- Lee Jones
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-11-03 00:00:00 +00:00
|
20
|
+
default_executable:
|
21
|
+
dependencies: []
|
22
|
+
|
23
|
+
description: Ruby C Extension for shadow access
|
24
|
+
email: ops@railsmachine.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions:
|
28
|
+
- ext/shadow/extconf.rb
|
29
|
+
extra_rdoc_files: []
|
30
|
+
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- README.rdoc
|
34
|
+
- Rakefile
|
35
|
+
- ext/shadow/extconf.rb
|
36
|
+
- ext/shadow/shadow.c
|
37
|
+
- lib/libshadow.rb
|
38
|
+
- libshadow.gemspec
|
39
|
+
has_rdoc: true
|
40
|
+
homepage: http://github.com/railsmachine/libshadow
|
41
|
+
licenses: []
|
42
|
+
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
|
46
|
+
require_paths:
|
47
|
+
- lib
|
48
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ">="
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 3
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
requirements: []
|
67
|
+
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.3.7
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: shadow.h
|
73
|
+
test_files: []
|
74
|
+
|