gitlab-ruby-shadow 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/HISTORY +99 -0
- data/LICENSE +9 -0
- data/MANIFEST +11 -0
- data/README +96 -0
- data/README.euc +80 -0
- data/extconf.rb +76 -0
- data/pwd/depend +1 -0
- data/pwd/shadow.c +130 -0
- data/ruby-shadow.gemspec +24 -0
- data/shadow/depend +1 -0
- data/shadow/shadow.c +284 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aee99b5c59047c6d7c94673bf204a497f40c97541f3d89af29adc98a47675b49
|
4
|
+
data.tar.gz: 825ad4a839b70a22eecab32781e7fff72bf39fdade301917178c76dcdd9aaa4e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e6877d3336cb327747d0faec021fe6624137aadd69210fd8c3d924199477bf3461ae0ff124bfbdbc40b97f025ba00ca5bdafb1398e68ead2b5f6aa0d061dc4ee
|
7
|
+
data.tar.gz: 326c6526713e2f423d5c924c29e4240d2225c5eedd9beaef218b0cc60bb7c644c77b749ae7b6c6fdf9ade060e84622515b46410f11c52ffa20c9715342fb3377
|
data/HISTORY
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
[2021/12/01]
|
2
|
+
* Version 2.5.1
|
3
|
+
- fixes for compiling for Ruby 3
|
4
|
+
|
5
|
+
[2015/10/06]
|
6
|
+
* Version 2.5.0
|
7
|
+
- fixes for compiling for rubinius, at long last
|
8
|
+
- TESTS
|
9
|
+
- add a few method aliases
|
10
|
+
|
11
|
+
[2014/12/02]
|
12
|
+
* Version 2.4.1
|
13
|
+
- sp_loginclass support should NOT have been added to password implementation
|
14
|
+
[2014/12/01]
|
15
|
+
* Version 2.4.0
|
16
|
+
- Add support for sp_loginclass via pwd.h
|
17
|
+
[2014/04/28]
|
18
|
+
* Version 2.3.3
|
19
|
+
- Added support for more BSDs, thanks to https://github.com/bsiegert.
|
20
|
+
- Simplified compatibility check, removing check for function not actually used in pwd.h implementations.
|
21
|
+
[2014/02/25]
|
22
|
+
[2013/12/18]
|
23
|
+
* Version 2.3.3
|
24
|
+
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.
|
25
|
+
[2013/11/13]
|
26
|
+
* Version 2.3.1
|
27
|
+
- Caleb Land<caleb.land@gmail.com>
|
28
|
+
Remove sgetspent on implementations using pwd.h
|
29
|
+
[2013/11/13]
|
30
|
+
* Version 2.3.0
|
31
|
+
- Caleb Land<caleb.land@gmail.com>
|
32
|
+
Merge OS X work into main gem. Fix bugs with OS X implementation and tweak support for FreeBSD.
|
33
|
+
See https://github.com/caleb/ruby-shadow/commit/20d98b7d9e3bbbef0b737affd3245590096a316c
|
34
|
+
- Add license file to Manifest.
|
35
|
+
[2013/02/25]
|
36
|
+
- Adam Palmblad<apalmblad@gmail.com>
|
37
|
+
Fix compilation issues with ruby 2.
|
38
|
+
|
39
|
+
[2012/04/17]
|
40
|
+
* Version 2.1.4
|
41
|
+
- MATSUU Takuto <matsuu@gentoo.org>
|
42
|
+
Change obsolete C function to its proper replacement.
|
43
|
+
* Version 2.1.3
|
44
|
+
- MATSUU Takuto <matsuu@gentoo.org>
|
45
|
+
Fix a typo in the C code for rb_shadow_putspent. Typo has been present since
|
46
|
+
ruby 1.9 code was added.
|
47
|
+
[2011/02/08]
|
48
|
+
* Version 2.1.2
|
49
|
+
- Jeff Blaine <>, Adam Palmblad <adam.palmblad@teampages.com>:
|
50
|
+
Fix issues with compiling against Solaris. Apparently solaris does not offer sgetspent
|
51
|
+
compiling against ruby 1.8; fixes were made to the ruby header path.
|
52
|
+
[2011/02/08]
|
53
|
+
* Version 2.1.1
|
54
|
+
- Eric Hankins <ssilver@stormsilver.net>: Looks like there was a minor bug in
|
55
|
+
compiling against ruby 1.8; fixes were made to the ruby header path.
|
56
|
+
[2011/01/27]
|
57
|
+
* Version 2.1
|
58
|
+
- Ian Marlier <imarlier@brightcove.com>: Make ruby-shadow compile under Ruby 1.9.2
|
59
|
+
* STR2CSTR macro was removed in Ruby 1.9.2, after being deprecated in Ruby 1.8. Change
|
60
|
+
to StringValuePtr() in its place.
|
61
|
+
|
62
|
+
[2010/07/27]
|
63
|
+
* Version 2.0
|
64
|
+
- Adam Palmblad <adam.palmblad@teampages.com>: Make ruby-shadow compile under Ruby 1.9
|
65
|
+
|
66
|
+
[1999/08/18]
|
67
|
+
* version 1.4.1
|
68
|
+
- extconf.rb supports glibc2(libc6).
|
69
|
+
|
70
|
+
[1999/03/09]
|
71
|
+
* version 1.4
|
72
|
+
- require ruby-1.3 or later version.
|
73
|
+
- sShadowPasswd,mShadow,eFileLock was renamed.
|
74
|
+
- FileLock class is inner class of Shadow Module.
|
75
|
+
- lock,unlock was changed.
|
76
|
+
- lock? method was added.
|
77
|
+
- getspent,fgetspent doesn't raise EOFError
|
78
|
+
- class hierarchy was changed.
|
79
|
+
Shadow Module
|
80
|
+
+ Passwd Module
|
81
|
+
+ Entry Structure
|
82
|
+
+ Group Module (not implemented yet)
|
83
|
+
+ Entry Structure (not implemented yet)
|
84
|
+
+ FileLock Class
|
85
|
+
|
86
|
+
[1998/12/17]
|
87
|
+
* version 1.3
|
88
|
+
- require ruby-1.1d0 or later version.
|
89
|
+
|
90
|
+
[1998/10/31]
|
91
|
+
* version 1.2
|
92
|
+
- only some bug fix.
|
93
|
+
|
94
|
+
[1998/08/31]
|
95
|
+
* version 1.1
|
96
|
+
- structure Shadow::ShadowPasswd is added.
|
97
|
+
|
98
|
+
[1998/07/15]
|
99
|
+
* version 1.0 released.
|
data/LICENSE
ADDED
data/MANIFEST
ADDED
data/README
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
Shadow Password module
|
2
|
+
|
3
|
+
Copyright (C) 1998-1999 Takaaki Tateishi <ttate@jaist.ac.jp>
|
4
|
+
Modified at: <1999/8/19 06:47:14 by ttate>
|
5
|
+
License: See LICENSE
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
1. What's this
|
10
|
+
|
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, FreeBSD and OpenBSD.
|
14
|
+
The functions found are translated to their equivalents in libshadow.
|
15
|
+
|
16
|
+
Note
|
17
|
+
|
18
|
+
2. install
|
19
|
+
|
20
|
+
ruby extconf.rb
|
21
|
+
make # use gmake on FreeBSD
|
22
|
+
(make install)
|
23
|
+
|
24
|
+
* Note:
|
25
|
+
Version 2 was developed to compile on Ruby 1.9. 1.8 compatibility should be
|
26
|
+
still present, but no promises about earlier versions of Ruby.
|
27
|
+
|
28
|
+
3. Shadow::Passwd module's methods
|
29
|
+
________________________________________________________________________
|
30
|
+
Method | Linux | Solaris | OS X | *BSD
|
31
|
+
________________________________________________________________________
|
32
|
+
getspent | * | * | * | *
|
33
|
+
getspnam(name) | * | * | * | *
|
34
|
+
from_user_name(name) (alias of above) | * | * | * | *
|
35
|
+
setspent | * | * | * | *
|
36
|
+
endspent | * | * | * | *
|
37
|
+
fgetspent(file) | * | * | N | N
|
38
|
+
sgetspent(str) | * | N | N | N
|
39
|
+
putspent(entry,file) | * | * | N | N
|
40
|
+
add_password_entry (alias of above ) | * | * | N | N
|
41
|
+
lckpwdf,lock | * | * | N | N
|
42
|
+
ulckpwdf,unlock | * | * | N | N
|
43
|
+
lock? | * | * | N | N
|
44
|
+
|
45
|
+
Check the implementation in use via Shadow::IMPLEMENTATION.
|
46
|
+
|
47
|
+
4. Structure
|
48
|
+
|
49
|
+
Shadow::Passwd::Entry (Struct::PasswdEntry)
|
50
|
+
sp_namp - pointer to null-terminated user name.
|
51
|
+
sp_pwdp - pointer to null-terminated password.
|
52
|
+
sp_lstchg - days since Jan 1, 1970 password was last
|
53
|
+
changed.
|
54
|
+
sp_min - days before which password may not be changed.
|
55
|
+
sp_max - days after which password must be changed.
|
56
|
+
sp_warn - days before password is to expire that user is
|
57
|
+
warned of pending password expiration.
|
58
|
+
sp_inact - days after password expires that account is
|
59
|
+
considered inactive and disabled.
|
60
|
+
sp_expire - days since Jan 1, 1970 when account will be
|
61
|
+
disabled
|
62
|
+
sp_loginclass - pointer to null-terminated user login class.
|
63
|
+
|
64
|
+
|
65
|
+
5. Description
|
66
|
+
|
67
|
+
getspent, getspname, fgetspent and sgetspent each return
|
68
|
+
a structure Shadow::Passwd::Entry. getspent returns the
|
69
|
+
next entry from the file, and fgetspent returns the next
|
70
|
+
entry from the given stream. sgetspent returns a structure
|
71
|
+
Shadow::Passwd::Entry using the provided string as input.
|
72
|
+
getspnam searches from the current position in the file for
|
73
|
+
an entry matching name.
|
74
|
+
if you get EOF from each operation, you will get nil.
|
75
|
+
|
76
|
+
setspent and endspent may be used to begin and end, respe-
|
77
|
+
ctively, access to the shadow password file.
|
78
|
+
|
79
|
+
lckpwdf(lock) and ulckpwdf(unlock) methods should be used
|
80
|
+
to insure exclusive access to the /etc/shadow file.
|
81
|
+
when either method fail, Exception Shadow::FileLock is raised.
|
82
|
+
if you use lock as the iterator, unlock is automatically called
|
83
|
+
when you exit the iterator block.
|
84
|
+
|
85
|
+
6. Reference
|
86
|
+
|
87
|
+
* man shadow
|
88
|
+
* /usr/include/shadow.h
|
89
|
+
* Code at https://github.com/apalmblad/ruby-shadow
|
90
|
+
|
91
|
+
|
92
|
+
Original Author:
|
93
|
+
Takaaki Tateishi <ttate@jaist.ac.jp>
|
94
|
+
|
95
|
+
This GitHub repository is maintained by Adam Palmblad <adam.palmblad@teampages.com>. I'll
|
96
|
+
do my best to keep the repository reasonably up-to-date if you care to send pull requests.
|
data/README.euc
ADDED
@@ -0,0 +1,80 @@
|
|
1
|
+
Shadow Password module
|
2
|
+
|
3
|
+
Copyright (C) 1998-1999 Takaaki Tateishi <ttate@jaist.ac.jp>
|
4
|
+
Modified at: <1999/8/19 06:48:01 by ttate>
|
5
|
+
License: Free for any use with your own risk!
|
6
|
+
|
7
|
+
|
8
|
+
1. ����
|
9
|
+
|
10
|
+
linux�ˤ�����shadow password�ե����������
|
11
|
+
�Υ⥸�塼�롣
|
12
|
+
|
13
|
+
|
14
|
+
2. ���ȡ���
|
15
|
+
|
16
|
+
ruby extconf.rb
|
17
|
+
make
|
18
|
+
make install
|
19
|
+
|
20
|
+
* ����
|
21
|
+
shadow-1.3�Ǥ�ruby-1.3�⤷���Ϥ���ʹߤΥС������
|
22
|
+
��ɬ�פǤ���
|
23
|
+
|
24
|
+
3. Shadow::Passwd�⥸�塼��Υ�å�ã
|
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
|
+
4. Structure
|
38
|
+
|
39
|
+
Shadow::Passwd::Entry (Struct::PasswdEntry)
|
40
|
+
sp_namp - pointer to null-terminated user name.
|
41
|
+
sp_pwdp - pointer to null-terminated password.
|
42
|
+
sp_lstchg - days since Jan 1, 1970 password was last
|
43
|
+
changed.
|
44
|
+
sp_min - days before which password may not be changed.
|
45
|
+
sp_max - days after which password must be changed.
|
46
|
+
sp_warn - days before password is to expire that user is
|
47
|
+
warned of pending password expiration.
|
48
|
+
sp_inact - days after password expires that account is
|
49
|
+
considered inactive and disabled.
|
50
|
+
sp_expire - days since Jan 1, 1970 when account will be
|
51
|
+
|
52
|
+
|
53
|
+
5. ����
|
54
|
+
|
55
|
+
getspent, getspname, fgetspent, sgetspent��Shadow::Passwd::Entry
|
56
|
+
���ȥ饯������֤��ޤ���getspent �ϥե����뤫�鼡�Υѥ���
|
57
|
+
���ɥ���ȥ���֤���fgetspent ��Ϳ����줿IO���鼡�Υ����
|
58
|
+
����֤��ޤ���sgetspent��Ϳ����줿ʸ����Shadow::Passwd::Entry
|
59
|
+
���ȥ饯������֤��ޤ���getspnam�ϥ桼��̾��Ϳ�����/etc/shadow
|
60
|
+
���餽�Υ桼����Shadow::Passwd::Entry���ȥ饯������֤��ޤ���
|
61
|
+
�ե�����ν�ü��ã�����nil���ͤ��֤��ޤ���
|
62
|
+
|
63
|
+
setspent,endspent�Ϥ��줾�졢�ե�����ؤΥ��������ΤϤ����
|
64
|
+
�����˻Ȥ��ޤ���
|
65
|
+
|
66
|
+
lckpwdf(lock),ulckpwdf(unlock)��/etc/shadow�ؤ���¾Ū��������
|
67
|
+
��¸����뤿��ˤ���ޤ���
|
68
|
+
lock�˼��Ԥ����Shadow::FileLock�Ȥ����㳰��ȯ�������ޤ���
|
69
|
+
lock�ƥ졼���Ȥ��ƻȤ����Ȥˤ�äơ����ƥ졼���֥��å���ȴ����
|
70
|
+
�Ȥ��˼�ưŪ��unlock��Ԥʤ��ޤ���
|
71
|
+
|
72
|
+
|
73
|
+
6. ����
|
74
|
+
|
75
|
+
* man shadow
|
76
|
+
* /usr/include/shadow.h
|
77
|
+
|
78
|
+
|
79
|
+
|
80
|
+
ttate@jaist.ac.jp
|
data/extconf.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
# extconf.rb
|
3
|
+
#
|
4
|
+
# Modified at: <1999/8/19 06:38:55 by ttate>
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'mkmf'
|
8
|
+
require 'rbconfig'
|
9
|
+
|
10
|
+
$CFLAGS = case RUBY_VERSION
|
11
|
+
when /^1\.9/; '-DRUBY19'
|
12
|
+
when /^2\./; '-DRUBY19'
|
13
|
+
when /^3\./; '-DRUBY19'
|
14
|
+
else; ''
|
15
|
+
end
|
16
|
+
|
17
|
+
RbConfig::MAKEFILE_CONFIG["CC"] = ENV["CC"] if ENV["CC"]
|
18
|
+
|
19
|
+
if RbConfig::MAKEFILE_CONFIG["CC"] =~ /gcc|clang/
|
20
|
+
$CFLAGS << " -O3" unless $CFLAGS[/-O\d/]
|
21
|
+
$CFLAGS << " -Wall"
|
22
|
+
end
|
23
|
+
|
24
|
+
implementation = case RbConfig::CONFIG['host_os']
|
25
|
+
when /linux/i; 'shadow'
|
26
|
+
when /sunos|solaris/i; 'shadow'
|
27
|
+
when /freebsd|mirbsd|netbsd|openbsd/i; 'pwd'
|
28
|
+
when /darwin/i; 'pwd'
|
29
|
+
else; nil
|
30
|
+
"This library works on OS X, FreeBSD, MirBSD, NetBSD, OpenBSD, Solaris and Linux."
|
31
|
+
end
|
32
|
+
|
33
|
+
ok = true
|
34
|
+
|
35
|
+
case implementation
|
36
|
+
when 'shadow'
|
37
|
+
#$LDFLAGS = "-lshadow"
|
38
|
+
|
39
|
+
if( ! (ok &= have_library("shadow","getspent")) )
|
40
|
+
$LDFLAGS = ""
|
41
|
+
ok = have_func("getspent")
|
42
|
+
end
|
43
|
+
|
44
|
+
ok &= have_func("fgetspent")
|
45
|
+
ok &= have_func("setspent")
|
46
|
+
ok &= have_func("endspent")
|
47
|
+
ok &= have_func("lckpwdf")
|
48
|
+
ok &= have_func("ulckpwdf")
|
49
|
+
|
50
|
+
if ok
|
51
|
+
if !have_func("sgetspent")
|
52
|
+
$CFLAGS += ' -DSOLARIS'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
when 'pwd'
|
56
|
+
ok &= have_func("endpwent")
|
57
|
+
ok &= have_func("getpwent")
|
58
|
+
ok &= have_func("getpwnam")
|
59
|
+
ok &= have_func("getpwuid")
|
60
|
+
ok &= have_func("setpassent")
|
61
|
+
ok &= have_func("setpwent")
|
62
|
+
|
63
|
+
have_header("uuid/uuid.h")
|
64
|
+
have_header("uuid.h")
|
65
|
+
else
|
66
|
+
ok = false
|
67
|
+
end
|
68
|
+
|
69
|
+
have_header( "ruby/io.h")
|
70
|
+
|
71
|
+
if ok
|
72
|
+
|
73
|
+
create_makefile("shadow", implementation)
|
74
|
+
else
|
75
|
+
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."
|
76
|
+
end
|
data/pwd/depend
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
shadow.o: shadow.c
|
data/pwd/shadow.c
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
/*
|
2
|
+
* shadow.c
|
3
|
+
*
|
4
|
+
* Ruby extention module for using FreeBSD/OpenBSD/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 HAVE_RUBY_IO_H
|
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
|
+
/* Hmm. Why custom pw_change instead of sp_lstchg? */
|
58
|
+
return rb_struct_new(rb_sPasswdEntry,
|
59
|
+
rb_str_new2(entry->pw_name), /* sp_namp */
|
60
|
+
rb_str_new2(entry->pw_passwd), /* sp_pwdp, encryped password */
|
61
|
+
Qnil, /* sp_lstchg, date when the password was last changed (in days since Jan 1, 1970) */
|
62
|
+
Qnil, /* sp_min, days that password must stay same */
|
63
|
+
Qnil, /* sp_max, days until password changes. */
|
64
|
+
Qnil, /* sp_warn, days before expiration where user is warned */
|
65
|
+
Qnil, /* sp_inact, days after password expiration that account becomes inactive */
|
66
|
+
INT2FIX(difftime(entry->pw_change, 0) / (24*60*60)), /* pw_change */
|
67
|
+
INT2FIX(difftime(entry->pw_expire, 0) / (24*60*60)), /* sp_expire */
|
68
|
+
Qnil, /* sp_flag */
|
69
|
+
rb_str_new2(entry->pw_class), /* sp_loginclass, user access class */
|
70
|
+
NULL);
|
71
|
+
}
|
72
|
+
|
73
|
+
static VALUE
|
74
|
+
rb_shadow_getspent(VALUE self)
|
75
|
+
{
|
76
|
+
PWTYPE *entry;
|
77
|
+
VALUE result;
|
78
|
+
entry = getpwent();
|
79
|
+
|
80
|
+
if( entry == NULL )
|
81
|
+
return Qnil;
|
82
|
+
|
83
|
+
result = convert_pw_struct( entry );
|
84
|
+
return result;
|
85
|
+
}
|
86
|
+
|
87
|
+
static VALUE
|
88
|
+
rb_shadow_getspnam(VALUE self, VALUE name)
|
89
|
+
{
|
90
|
+
PWTYPE *entry;
|
91
|
+
VALUE result;
|
92
|
+
|
93
|
+
if( TYPE(name) != T_STRING )
|
94
|
+
rb_raise(rb_eException,"argument must be a string.");
|
95
|
+
entry = getpwnam(StringValuePtr(name));
|
96
|
+
|
97
|
+
if( entry == NULL )
|
98
|
+
return Qnil;
|
99
|
+
|
100
|
+
result = convert_pw_struct( entry );
|
101
|
+
return result;
|
102
|
+
}
|
103
|
+
|
104
|
+
void
|
105
|
+
Init_shadow()
|
106
|
+
{
|
107
|
+
rb_sPasswdEntry = rb_struct_define("PasswdEntry",
|
108
|
+
"sp_namp","sp_pwdp","sp_lstchg",
|
109
|
+
"sp_min","sp_max","sp_warn",
|
110
|
+
"sp_inact","pw_change",
|
111
|
+
"sp_expire","sp_flag",
|
112
|
+
"sp_loginclass", NULL);
|
113
|
+
rb_sGroupEntry = rb_struct_define("GroupEntry",
|
114
|
+
"sg_name","sg_passwd",
|
115
|
+
"sg_adm","sg_mem",NULL);
|
116
|
+
|
117
|
+
rb_mShadow = rb_define_module("Shadow");
|
118
|
+
rb_define_const( rb_mShadow, "IMPLEMENTATION", rb_str_new_cstr( "PWD" ) );
|
119
|
+
rb_eFileLock = rb_define_class_under(rb_mShadow,"FileLock",rb_eException);
|
120
|
+
rb_mPasswd = rb_define_module_under(rb_mShadow,"Passwd");
|
121
|
+
rb_define_const(rb_mPasswd,"Entry",rb_sPasswdEntry);
|
122
|
+
rb_mGroup = rb_define_module_under(rb_mShadow,"Group");
|
123
|
+
rb_define_const(rb_mGroup,"Entry",rb_sGroupEntry);
|
124
|
+
|
125
|
+
rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0);
|
126
|
+
rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0);
|
127
|
+
rb_define_module_function(rb_mPasswd,"getspent",rb_shadow_getspent,0);
|
128
|
+
rb_define_module_function(rb_mPasswd,"getspnam",rb_shadow_getspnam,1);
|
129
|
+
rb_define_module_function(rb_mPasswd,"from_user_name",rb_shadow_getspnam,1);
|
130
|
+
}
|
data/ruby-shadow.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.authors = ['Adam Palmblad',
|
5
|
+
'Eric Hankins',
|
6
|
+
'Ian Marlier',
|
7
|
+
'Jeff Blaine',
|
8
|
+
'Remi Broemeling',
|
9
|
+
'Takaaki Tateishi']
|
10
|
+
|
11
|
+
spec.description = 'This module provides access to shadow passwords on Linux, OSX, FreeBSD, OpenBSD, and Solaris'
|
12
|
+
spec.email = ['adam.palmblad@teampages.com']
|
13
|
+
spec.extensions = ['extconf.rb']
|
14
|
+
spec.files = []
|
15
|
+
File.open('MANIFEST').each do |file|
|
16
|
+
spec.files << file.chomp
|
17
|
+
end
|
18
|
+
spec.homepage = 'https://gitlab.com/gitlab-org/ruby/gems/ruby-shadow'
|
19
|
+
spec.name = 'gitlab-ruby-shadow'
|
20
|
+
spec.required_ruby_version = ['>= 1.8']
|
21
|
+
spec.summary = '*nix Shadow Password Module'
|
22
|
+
spec.version = '2.5.1'
|
23
|
+
spec.license = "Unlicense"
|
24
|
+
end
|
data/shadow/depend
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
shadow.o: shadow.c
|
data/shadow/shadow.c
ADDED
@@ -0,0 +1,284 @@
|
|
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
|
+
*/
|
9
|
+
|
10
|
+
#include <shadow.h>
|
11
|
+
#include "ruby.h"
|
12
|
+
#ifdef HAVE_RUBY_IO_H
|
13
|
+
#include "ruby/io.h"
|
14
|
+
#else
|
15
|
+
#include "rubyio.h"
|
16
|
+
#endif
|
17
|
+
|
18
|
+
#ifdef RUBY19
|
19
|
+
#define file_ptr(x) rb_io_stdio_file(x)
|
20
|
+
#else
|
21
|
+
#define file_ptr(x) (x)->fd
|
22
|
+
#endif
|
23
|
+
|
24
|
+
#define NUM_FIELDS 10
|
25
|
+
|
26
|
+
static VALUE rb_mShadow;
|
27
|
+
static VALUE rb_mPasswd;
|
28
|
+
static VALUE rb_sPasswdEntry;
|
29
|
+
static VALUE rb_mGroup;
|
30
|
+
static VALUE rb_sGroupEntry;
|
31
|
+
static VALUE rb_eFileLock;
|
32
|
+
|
33
|
+
|
34
|
+
static VALUE convert_pw_struct( struct spwd *entry )
|
35
|
+
{
|
36
|
+
return rb_struct_new(rb_sPasswdEntry,
|
37
|
+
rb_str_new2(entry->sp_namp),
|
38
|
+
rb_str_new2(entry->sp_pwdp),
|
39
|
+
INT2FIX(entry->sp_lstchg),
|
40
|
+
INT2FIX(entry->sp_min),
|
41
|
+
INT2FIX(entry->sp_max),
|
42
|
+
INT2FIX(entry->sp_warn),
|
43
|
+
INT2FIX(entry->sp_inact),
|
44
|
+
Qnil, /* used by BSD, pw_change, date when the password expires, in days since Jan 1, 1970 */
|
45
|
+
INT2FIX(entry->sp_expire),
|
46
|
+
INT2FIX(entry->sp_flag),
|
47
|
+
Qnil,
|
48
|
+
NULL);
|
49
|
+
};
|
50
|
+
static VALUE
|
51
|
+
rb_shadow_setspent(VALUE self)
|
52
|
+
{
|
53
|
+
setspent();
|
54
|
+
return Qnil;
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
static VALUE
|
59
|
+
rb_shadow_endspent(VALUE self)
|
60
|
+
{
|
61
|
+
endspent();
|
62
|
+
return Qnil;
|
63
|
+
};
|
64
|
+
|
65
|
+
|
66
|
+
#ifndef SOLARIS
|
67
|
+
static VALUE
|
68
|
+
rb_shadow_sgetspent(VALUE self, VALUE str)
|
69
|
+
{
|
70
|
+
struct spwd *entry;
|
71
|
+
VALUE result;
|
72
|
+
|
73
|
+
if( TYPE(str) != T_STRING )
|
74
|
+
rb_raise(rb_eException,"argument must be a string.");
|
75
|
+
|
76
|
+
entry = sgetspent(StringValuePtr(str));
|
77
|
+
|
78
|
+
if( entry == NULL )
|
79
|
+
return Qnil;
|
80
|
+
|
81
|
+
result = convert_pw_struct( entry );
|
82
|
+
free(entry);
|
83
|
+
return result;
|
84
|
+
};
|
85
|
+
#endif
|
86
|
+
|
87
|
+
static VALUE
|
88
|
+
rb_shadow_fgetspent(VALUE self, VALUE file)
|
89
|
+
{
|
90
|
+
struct spwd *entry;
|
91
|
+
VALUE result;
|
92
|
+
|
93
|
+
if( TYPE(file) != T_FILE )
|
94
|
+
rb_raise(rb_eTypeError,"argument must be a File.");
|
95
|
+
entry = fgetspent( file_ptr( (RFILE(file)->fptr) ) );
|
96
|
+
|
97
|
+
if( entry == NULL )
|
98
|
+
return Qnil;
|
99
|
+
|
100
|
+
result = convert_pw_struct( entry );
|
101
|
+
return result;
|
102
|
+
};
|
103
|
+
|
104
|
+
static VALUE
|
105
|
+
rb_shadow_getspent(VALUE self)
|
106
|
+
{
|
107
|
+
struct spwd *entry;
|
108
|
+
VALUE result;
|
109
|
+
|
110
|
+
entry = getspent();
|
111
|
+
|
112
|
+
if( entry == NULL )
|
113
|
+
return Qnil;
|
114
|
+
|
115
|
+
return convert_pw_struct( entry );
|
116
|
+
};
|
117
|
+
|
118
|
+
static VALUE
|
119
|
+
rb_shadow_getspnam(VALUE self, VALUE name)
|
120
|
+
{
|
121
|
+
struct spwd *entry;
|
122
|
+
VALUE result;
|
123
|
+
|
124
|
+
if( TYPE(name) != T_STRING )
|
125
|
+
rb_raise(rb_eException,"argument must be a string.");
|
126
|
+
|
127
|
+
entry = getspnam(StringValuePtr(name));
|
128
|
+
|
129
|
+
if( entry == NULL )
|
130
|
+
return Qnil;
|
131
|
+
return convert_pw_struct( entry );
|
132
|
+
};
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
static VALUE
|
137
|
+
rb_shadow_putspent(VALUE self, VALUE entry, VALUE file)
|
138
|
+
{
|
139
|
+
struct spwd centry;
|
140
|
+
FILE* cfile;
|
141
|
+
VALUE val[NUM_FIELDS];
|
142
|
+
int i;
|
143
|
+
int result;
|
144
|
+
|
145
|
+
if( TYPE(file) != T_FILE )
|
146
|
+
rb_raise(rb_eTypeError,"argument must be a File.");
|
147
|
+
/*
|
148
|
+
for(i=0; i<NUM_FIELDS; i++)
|
149
|
+
{
|
150
|
+
val[i] = rb_ary_entry( entry, i ); //val[i] = RSTRUCT(entry)->ptr[i];
|
151
|
+
i//val[i] = rb_struct_aref( entry, i );
|
152
|
+
}
|
153
|
+
*/
|
154
|
+
cfile = file_ptr( RFILE(file)->fptr );
|
155
|
+
|
156
|
+
VALUE x = rb_ary_entry( entry, 0 );
|
157
|
+
centry.sp_namp = StringValuePtr( x );
|
158
|
+
x = rb_ary_entry( entry, 1 );
|
159
|
+
centry.sp_pwdp = StringValuePtr( x );
|
160
|
+
centry.sp_lstchg = FIX2INT( rb_ary_entry( entry, 2) );
|
161
|
+
centry.sp_min = FIX2INT( rb_ary_entry( entry, 3 ) );
|
162
|
+
centry.sp_max = FIX2INT( rb_ary_entry( entry, 4 ) );
|
163
|
+
centry.sp_warn = FIX2INT( rb_ary_entry( entry, 5 ));
|
164
|
+
centry.sp_inact = FIX2INT( rb_ary_entry( entry, 6 ) );
|
165
|
+
// missing 7 I think is put in to deal with beign similar to BSD returns, for the value pw_change.
|
166
|
+
centry.sp_expire = FIX2INT( rb_ary_entry( entry, 8 ) );
|
167
|
+
centry.sp_flag = FIX2INT( rb_ary_entry( entry, 9 ) );
|
168
|
+
|
169
|
+
result = putspent(¢ry,cfile);
|
170
|
+
|
171
|
+
if( result == -1 )
|
172
|
+
rb_raise(rb_eStandardError,"can't change password");
|
173
|
+
|
174
|
+
return Qtrue;
|
175
|
+
};
|
176
|
+
|
177
|
+
|
178
|
+
static VALUE
|
179
|
+
rb_shadow_lckpwdf(VALUE self)
|
180
|
+
{
|
181
|
+
int result;
|
182
|
+
result = lckpwdf();
|
183
|
+
if( result == -1 )
|
184
|
+
rb_raise(rb_eFileLock,"password file was locked");
|
185
|
+
else
|
186
|
+
return Qtrue;
|
187
|
+
};
|
188
|
+
|
189
|
+
static int in_lock;
|
190
|
+
|
191
|
+
static VALUE
|
192
|
+
rb_shadow_lock(VALUE self)
|
193
|
+
{
|
194
|
+
int result;
|
195
|
+
|
196
|
+
if( rb_block_given_p() ){
|
197
|
+
result = lckpwdf();
|
198
|
+
if( result == -1 ){
|
199
|
+
rb_raise(rb_eFileLock,"password file was locked");
|
200
|
+
}
|
201
|
+
else{
|
202
|
+
in_lock++;
|
203
|
+
rb_yield(Qnil);
|
204
|
+
in_lock--;
|
205
|
+
ulckpwdf();
|
206
|
+
};
|
207
|
+
return Qtrue;
|
208
|
+
}
|
209
|
+
else{
|
210
|
+
return rb_shadow_lckpwdf(self);
|
211
|
+
};
|
212
|
+
};
|
213
|
+
|
214
|
+
|
215
|
+
static VALUE
|
216
|
+
rb_shadow_ulckpwdf(VALUE self)
|
217
|
+
{
|
218
|
+
if( in_lock ){
|
219
|
+
rb_raise(rb_eFileLock,"you call unlock method in lock iterator.");
|
220
|
+
};
|
221
|
+
ulckpwdf();
|
222
|
+
return Qtrue;
|
223
|
+
};
|
224
|
+
|
225
|
+
static VALUE
|
226
|
+
rb_shadow_unlock(VALUE self)
|
227
|
+
{
|
228
|
+
return rb_shadow_ulckpwdf(self);
|
229
|
+
};
|
230
|
+
|
231
|
+
static VALUE
|
232
|
+
rb_shadow_lock_p(VALUE self)
|
233
|
+
{
|
234
|
+
int result;
|
235
|
+
|
236
|
+
result = lckpwdf();
|
237
|
+
if( result == -1 ){
|
238
|
+
return Qtrue;
|
239
|
+
}
|
240
|
+
else{
|
241
|
+
ulckpwdf();
|
242
|
+
return Qfalse;
|
243
|
+
};
|
244
|
+
};
|
245
|
+
|
246
|
+
|
247
|
+
void
|
248
|
+
Init_shadow()
|
249
|
+
{
|
250
|
+
rb_sPasswdEntry = rb_struct_define("PasswdEntry",
|
251
|
+
"sp_namp","sp_pwdp","sp_lstchg",
|
252
|
+
"sp_min","sp_max","sp_warn",
|
253
|
+
"sp_inact", "pw_change",
|
254
|
+
"sp_expire","sp_flag",
|
255
|
+
"sp_loginclass", NULL);
|
256
|
+
rb_sGroupEntry = rb_struct_define("GroupEntry",
|
257
|
+
"sg_name","sg_passwd",
|
258
|
+
"sg_adm","sg_mem",NULL);
|
259
|
+
|
260
|
+
rb_mShadow = rb_define_module("Shadow");
|
261
|
+
rb_define_const( rb_mShadow, "IMPLEMENTATION", rb_str_new_cstr( "SHADOW" ) );
|
262
|
+
rb_eFileLock = rb_define_class_under(rb_mShadow,"FileLock",rb_eException);
|
263
|
+
rb_mPasswd = rb_define_module_under(rb_mShadow,"Passwd");
|
264
|
+
rb_define_const(rb_mPasswd,"Entry",rb_sPasswdEntry);
|
265
|
+
rb_mGroup = rb_define_module_under(rb_mShadow,"Group");
|
266
|
+
rb_define_const(rb_mGroup,"Entry",rb_sGroupEntry);
|
267
|
+
|
268
|
+
rb_define_module_function(rb_mPasswd,"setspent",rb_shadow_setspent,0);
|
269
|
+
rb_define_module_function(rb_mPasswd,"endspent",rb_shadow_endspent,0);
|
270
|
+
#ifndef SOLARIS
|
271
|
+
rb_define_module_function(rb_mPasswd,"sgetspent",rb_shadow_sgetspent,1);
|
272
|
+
#endif
|
273
|
+
rb_define_module_function(rb_mPasswd,"fgetspent",rb_shadow_fgetspent,1);
|
274
|
+
rb_define_module_function(rb_mPasswd,"getspent",rb_shadow_getspent,0);
|
275
|
+
rb_define_module_function(rb_mPasswd,"getspnam",rb_shadow_getspnam,1);
|
276
|
+
rb_define_module_function(rb_mPasswd,"from_user_name",rb_shadow_getspnam,1);
|
277
|
+
rb_define_module_function(rb_mPasswd,"putspent",rb_shadow_putspent,2);
|
278
|
+
rb_define_module_function(rb_mPasswd,"add_password_entry",rb_shadow_putspent,2);
|
279
|
+
rb_define_module_function(rb_mPasswd,"lckpwdf",rb_shadow_lckpwdf,0);
|
280
|
+
rb_define_module_function(rb_mPasswd,"lock",rb_shadow_lock,0);
|
281
|
+
rb_define_module_function(rb_mPasswd,"ulckpwdf",rb_shadow_ulckpwdf,0);
|
282
|
+
rb_define_module_function(rb_mPasswd,"unlock",rb_shadow_unlock,0);
|
283
|
+
rb_define_module_function(rb_mPasswd,"lock?",rb_shadow_lock_p,0);
|
284
|
+
};
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gitlab-ruby-shadow
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 2.5.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Palmblad
|
8
|
+
- Eric Hankins
|
9
|
+
- Ian Marlier
|
10
|
+
- Jeff Blaine
|
11
|
+
- Remi Broemeling
|
12
|
+
- Takaaki Tateishi
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
date: 2024-02-07 00:00:00.000000000 Z
|
17
|
+
dependencies: []
|
18
|
+
description: This module provides access to shadow passwords on Linux, OSX, FreeBSD,
|
19
|
+
OpenBSD, and Solaris
|
20
|
+
email:
|
21
|
+
- adam.palmblad@teampages.com
|
22
|
+
executables: []
|
23
|
+
extensions:
|
24
|
+
- extconf.rb
|
25
|
+
extra_rdoc_files: []
|
26
|
+
files:
|
27
|
+
- HISTORY
|
28
|
+
- LICENSE
|
29
|
+
- MANIFEST
|
30
|
+
- README
|
31
|
+
- README.euc
|
32
|
+
- extconf.rb
|
33
|
+
- pwd/depend
|
34
|
+
- pwd/shadow.c
|
35
|
+
- ruby-shadow.gemspec
|
36
|
+
- shadow/depend
|
37
|
+
- shadow/shadow.c
|
38
|
+
homepage: https://gitlab.com/gitlab-org/ruby/gems/ruby-shadow
|
39
|
+
licenses:
|
40
|
+
- Unlicense
|
41
|
+
metadata: {}
|
42
|
+
post_install_message:
|
43
|
+
rdoc_options: []
|
44
|
+
require_paths:
|
45
|
+
- lib
|
46
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
47
|
+
requirements:
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: '1.8'
|
51
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
requirements: []
|
57
|
+
rubygems_version: 3.5.5
|
58
|
+
signing_key:
|
59
|
+
specification_version: 4
|
60
|
+
summary: "*nix Shadow Password Module"
|
61
|
+
test_files: []
|