etcutils 0.1.5-x86-linux

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ #include "extconf.h"
2
+ #include "ruby.h"
3
+
4
+ #define EUVERSION "0.1.5"
5
+
6
+ #ifdef HAVE_RUBY_IO_H
7
+ #include "ruby/io.h"
8
+ #else
9
+ #include "rubyio.h"
10
+ #endif
11
+
12
+ #ifdef HAVE_SHADOW_H
13
+ #include <shadow.h>
14
+ #endif
15
+ #ifdef HAVE_PWD_H
16
+ #include <pwd.h>
17
+ #endif
18
+ #ifdef HAVE_GSHADOW_H
19
+ #include <gshadow.h>
20
+ #endif
21
+ #ifdef HAVE_GSHADOW__H
22
+ #include <gshadow_.h>
23
+ #endif
24
+ #ifdef HAVE_GRP_H
25
+ #include <grp.h>
26
+ #endif
27
+
28
+ #ifndef PASSWD
29
+ #define PASSWD "/etc/passwd"
30
+ #endif
31
+
32
+ #ifndef SHADOW
33
+ #define SHADOW "/etc/shadow"
34
+ #endif
35
+
36
+ #ifndef GROUP
37
+ #define GROUP "/etc/group"
38
+ #endif
39
+
40
+ #ifndef GSHADOW
41
+ #define GSHADOW "/etc/gshadow"
42
+ #endif
43
+
44
+ #ifdef HAVE_ST_SG_NAMP
45
+ #define SGRP_NAME(s) (s)->sg_namp
46
+ #else
47
+ #define SGRP_NAME(s) (s)->sg_name
48
+ #endif
49
+
50
+ #ifdef HAVE_STRUCT_RB_IO_T_PATHV
51
+ #define RFILE_PATH(x) (RFILE(x)->fptr)->pathv
52
+ #else
53
+ #define RFILE_PATH(x) ( setup_safe_str( (RFILE(x)->fptr)->path ) )
54
+ #endif
55
+
56
+ #ifdef HAVE_RB_IO_STDIO_FILE
57
+ #define RFILE_FPTR(x) rb_io_stdio_file( RFILE(x)->fptr )
58
+ #else
59
+ #define RFILE_FPTR(x) (RFILE(x)->fptr)->f
60
+ #endif
61
+
62
+ #ifndef UIDT2NUM
63
+ #define UIDT2NUM(v) UINT2NUM(v)
64
+ #endif
65
+ #ifndef NUM2UIDT
66
+ #define NUM2UIDT(v) NUM2UINT(v)
67
+ #endif
68
+ #ifndef GIDT2NUM
69
+ #define GIDT2NUM(v) UINT2NUM(v)
70
+ #endif
71
+ #ifndef NUM2GIDT
72
+ #define NUM2GIDT(v) NUM2UINT(v)
73
+ #endif
74
+
75
+ static VALUE cShadow;
76
+ static VALUE cGShadow;
77
+ static VALUE cPasswd;
78
+ static VALUE cGroup;
79
+
80
+ /* EtcUtils helper functions */
81
+ extern uid_t uid_global;
82
+ extern gid_t gid_global;
83
+
84
+ static VALUE next_uid( int argc, VALUE *argv, VALUE self);
85
+ static VALUE next_gid( int argc, VALUE *argv, VALUE self);
86
+ static void ensure_file(VALUE io);
87
+ static void etcutils_errno(VALUE str);
88
+
89
+ static VALUE setup_safe_str(const char *str);
90
+ static VALUE setup_safe_array(char **arr);
91
+ static char** setup_char_members(VALUE ary);
92
+ static void free_char_members(char ** mem, int c);
93
+
94
+ static VALUE setup_passwd(struct passwd *pwd);
95
+ static VALUE setup_shadow(struct spwd *shadow);
96
+ static VALUE setup_group(struct group *grp);
97
+ static VALUE setup_gshadow(struct sgrp *sgroup);
98
+ /* End of helper functions */
@@ -0,0 +1,45 @@
1
+ #
2
+ # extconf.rb
3
+ #
4
+ # Modified at: <2013/07/04 16:12:45 by dcampbell>
5
+ #
6
+
7
+ require 'mkmf'
8
+
9
+ have_header('ruby/io.h')
10
+ have_struct_member("struct rb_io_t", "pathv", "ruby/io.h")
11
+ have_func('rb_io_stdio_file')
12
+
13
+ have_header('etcutils.h')
14
+
15
+ if (have_header('pwd.h') && have_header('grp.h'))
16
+ short_v = ['pw','gr']
17
+
18
+ if have_header('shadow.h')
19
+ short_v << 'sp'
20
+ end
21
+
22
+ ["gshadow.h","gshadow_.h"].each do |h|
23
+ short_v << 'sg'
24
+ if have_header(h)
25
+ nam = "sg_nam"+ (h =~ /_/ ? 'e' : 'p')
26
+ [nam, "sg_passwd", "sg_adm", "sg_mem"].each do |m|
27
+ have_struct_member("struct sgrp", m, h)
28
+ end
29
+ end
30
+ end
31
+
32
+ have_func("lckpwdf")
33
+ have_func("ulckpwdf")
34
+
35
+ short_v.each do |h|
36
+ ["get#{h}ent","sget#{h}ent","fget#{h}ent","put#{h}ent","set#{h}ent","end#{h}ent"].each do |func|
37
+ have_func(func)
38
+ end
39
+ end
40
+
41
+ create_header
42
+ create_makefile("etcutils")
43
+ else
44
+ puts "This system is not managed by passwd/group files.","Exiting"
45
+ end
@@ -0,0 +1,4 @@
1
+ require 'test/unit'
2
+ require 'etcutils'
3
+
4
+ class Test::Unit::TestCase; include EtcUtils; end
@@ -0,0 +1,71 @@
1
+ require 'etcutils_test_helper'
2
+
3
+ class EtcUtilsTest < Test::Unit::TestCase
4
+ SG_MAP = {
5
+ :pw => { :file => PASSWD, :ext => 'd' },
6
+ :sp => { :file => SHADOW, :ext => 'wd' },
7
+ :gr => { :file => GROUP, :ext => 'p' },
8
+ :sg => { :file => GSHADOW, :ext => 'rp' },
9
+ }
10
+
11
+ def test_locking
12
+ assert_block "Couldn't run a block inside of lock()" do
13
+ lock { assert locked? }
14
+ !locked?
15
+ end
16
+ end
17
+
18
+ def test_locked_after_exception
19
+ assert_block "Files remained locked when an exception is raised inside of lock()" do
20
+ begin
21
+ lock { raise "foobar" }
22
+ rescue
23
+ !locked?
24
+ end
25
+ end
26
+ end
27
+
28
+ def test_nsswitch_conf_gshadow
29
+ assert_block "\n#{'*' * 75}
30
+ nsswitch.conf may be misconfigured. Consider adding the below to /etc/nsswitch.conf.
31
+ gshadow:\tfiles
32
+ See 'http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=699089' for more.\n" do
33
+ setsgent
34
+ !!getsgent
35
+ end
36
+ end
37
+
38
+ SG_MAP.keys.each do |xx|
39
+ define_method("test_fget#{xx}ent_cp#{SG_MAP[xx][:file].gsub('/','_')}") {
40
+ tmp_fn = "/tmp/_fget#{xx}ent_test"
41
+ assert_nothing_raised do
42
+ fh = File.open(SG_MAP[xx][:file], 'r')
43
+ File.open(tmp_fn, File::RDWR|File::CREAT, 0600) { |tmp_fh|
44
+ while ( ent = EtcUtils.send("fget#{xx}ent", fh) )
45
+ ent.fputs(tmp_fh)
46
+ end
47
+ }
48
+ fh.close
49
+ assert FileUtils.compare_file(SG_MAP[xx][:file], tmp_fn) == true
50
+ FileUtils.remove_file(tmp_fn);
51
+ end
52
+ }
53
+
54
+ define_method("test_get#{xx}") {
55
+ assert_nothing_raised do
56
+ EtcUtils.send("set#{xx}ent")
57
+ while ( ent = EtcUtils.send("get#{xx}ent")); nil; end
58
+ end
59
+ }
60
+
61
+ m = "find_#{xx}#{SG_MAP[xx][:ext]}"
62
+ define_method("test_#{m}_typeerr") { assert_raise TypeError do; EtcUtils.send(m,{}); end }
63
+ define_method("test_#{m}_find_int") { assert EtcUtils.send(m, 0).name.eql? "root" }
64
+ define_method("test_#{m}_find_str") { assert EtcUtils.send(m, 'root').name.eql? "root" }
65
+ end
66
+
67
+ def test_sgetXXent
68
+ assert sgetspent(find_spwd('root').to_entry).name.eql? "root"
69
+ assert sgetsgent(find_sgrp('root').to_entry).name.eql? "root"
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: etcutils
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: x86-linux
6
+ authors:
7
+ - David Campbell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2014-04-23 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: bundler
16
+ prerelease: false
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: "1.3"
22
+ type: :development
23
+ version_requirements: *id001
24
+ - !ruby/object:Gem::Dependency
25
+ name: rake
26
+ prerelease: false
27
+ requirement: &id002 !ruby/object:Gem::Requirement
28
+ requirements:
29
+ - &id003
30
+ - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
36
+ name: rake-compiler
37
+ prerelease: false
38
+ requirement: &id004 !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - *id003
41
+ type: :development
42
+ version_requirements: *id004
43
+ description: Ruby Extension that allows for reads and writes to the /etc user db.
44
+ email: david@mrcampbell.org
45
+ executables: []
46
+
47
+ extensions:
48
+ - ext/etcutils/extconf.rb
49
+ extra_rdoc_files: []
50
+
51
+ files:
52
+ - .gitignore
53
+ - LICENSE
54
+ - README.md
55
+ - Rakefile
56
+ - etcutils.gemspec
57
+ - ext/etcutils/etcutils.c
58
+ - ext/etcutils/etcutils.h
59
+ - ext/etcutils/extconf.rb
60
+ - tests/etcutils_test_helper.rb
61
+ - tests/test_etc_utils.rb
62
+ homepage: https://github.com/dacamp/etcutils
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+
67
+ post_install_message:
68
+ rdoc_options: []
69
+
70
+ require_paths:
71
+ - .
72
+ required_ruby_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - *id003
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - *id003
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 2.2.2
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: This gem is specific to *nix environments. It's a rewrite of libshadow-ruby allowing for reads and writes to passwd,shadow,group, and gshadow /etc files. There are probably still bugs, so use at your own risk.
85
+ test_files: []
86
+