etc 0.2.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -0
- data/README.md +19 -4
- data/etc.gemspec +4 -3
- data/ext/etc/etc.c +10 -7
- data/ext/etc/extconf.rb +4 -2
- data/test/etc/test_etc.rb +3 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 470f56643e5fb28930ac3d0d1cb4200778c74610c06d958a2c5264eed49fd6ed
|
4
|
+
data.tar.gz: 311937e0471e67df04429ca390b9dd7240e7cb1bef91ca4f06232be0966f8d4f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6afef3a83d16491cf6ae5baf9cd0dc496681cb06a58647e9b7389ff149dbaa548a372642657615392ca1b087aaaa94ef3e72a3f75bb25e12a9172e29752a272a
|
7
|
+
data.tar.gz: ee873bfdd434c3e5f501890dcd0707dbed08f6deb68ffb918d2b5c3823612db8e1e3b34286f8b32a032a62ed5089fef9a07e0a07832e9fc37d1c725c8b30a2d0
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,8 +1,12 @@
|
|
1
1
|
# Etc
|
2
2
|
|
3
|
-
|
3
|
+
[![Build Status](https://travis-ci.org/ruby/etc.svg?branch=master)](https://travis-ci.org/ruby/etc)
|
4
4
|
|
5
|
-
|
5
|
+
The Etc module provides access to information typically stored in files in the /etc directory on Unix systems.
|
6
|
+
|
7
|
+
The information accessible consists of the information found in the `/etc/passwd` and `/etc/group` files, plus information about he system's temporary directory (/tmp) and configuration directory (/etc).
|
8
|
+
|
9
|
+
The Etc module provides a more reliable way to access information about the logged in user than environment variables such as +$USER+.
|
6
10
|
|
7
11
|
## Installation
|
8
12
|
|
@@ -22,7 +26,18 @@ Or install it yourself as:
|
|
22
26
|
|
23
27
|
## Usage
|
24
28
|
|
25
|
-
|
29
|
+
```
|
30
|
+
require 'etc'
|
31
|
+
|
32
|
+
login = Etc.getlogin
|
33
|
+
info = Etc.getpwnam(login)
|
34
|
+
username = info.gecos.split(/,/).first
|
35
|
+
puts "Hello #{username}, I see your login name is #{login}"
|
36
|
+
```
|
37
|
+
|
38
|
+
Note that the methods provided by this module are not always secure. It should be used for informational purposes, and not for security.
|
39
|
+
|
40
|
+
All operations defined in this module are class methods, so that you can include the Etc module into your class.
|
26
41
|
|
27
42
|
## Development
|
28
43
|
|
@@ -36,4 +51,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/ruby/e
|
|
36
51
|
|
37
52
|
## License
|
38
53
|
|
39
|
-
The gem is available as open source under the terms of the [
|
54
|
+
The gem is available as open source under the terms of the [2-Clause BSD License](https://opensource.org/licenses/BSD-2-Clause).
|
data/etc.gemspec
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
# coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
4
|
Gem::Specification.new do |spec|
|
4
5
|
spec.name = "etc"
|
5
|
-
spec.version = "0.
|
6
|
-
spec.date = '2017-
|
6
|
+
spec.version = "1.0.0"
|
7
|
+
spec.date = '2017-12-13'
|
7
8
|
spec.authors = ["Yukihiro Matsumoto"]
|
8
9
|
spec.email = ["matz@ruby-lang.org"]
|
9
10
|
|
@@ -32,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
32
33
|
spec.require_paths = ["lib"]
|
33
34
|
spec.extensions = %w{ext/etc/extconf.rb}
|
34
35
|
|
35
|
-
spec.required_ruby_version = ">= 2.
|
36
|
+
spec.required_ruby_version = ">= 2.3.0"
|
36
37
|
|
37
38
|
spec.add_development_dependency "bundler"
|
38
39
|
spec.add_development_dependency "rake"
|
data/ext/etc/etc.c
CHANGED
@@ -215,9 +215,10 @@ etc_getpwnam(VALUE obj, VALUE nam)
|
|
215
215
|
{
|
216
216
|
#ifdef HAVE_GETPWENT
|
217
217
|
struct passwd *pwd;
|
218
|
+
const char *p = StringValueCStr(nam);
|
218
219
|
|
219
|
-
|
220
|
-
pwd = getpwnam(
|
220
|
+
rb_check_safe_obj(nam);
|
221
|
+
pwd = getpwnam(p);
|
221
222
|
if (pwd == 0) rb_raise(rb_eArgError, "can't find user for %"PRIsVALUE, nam);
|
222
223
|
return setup_passwd(pwd);
|
223
224
|
#else
|
@@ -458,9 +459,10 @@ etc_getgrnam(VALUE obj, VALUE nam)
|
|
458
459
|
{
|
459
460
|
#ifdef HAVE_GETGRENT
|
460
461
|
struct group *grp;
|
462
|
+
const char *p = StringValueCStr(nam);
|
461
463
|
|
462
|
-
|
463
|
-
grp = getgrnam(
|
464
|
+
rb_check_safe_obj(nam);
|
465
|
+
grp = getgrnam(p);
|
464
466
|
if (grp == 0) rb_raise(rb_eArgError, "can't find group for %"PRIsVALUE, nam);
|
465
467
|
return setup_group(grp);
|
466
468
|
#else
|
@@ -625,8 +627,9 @@ VALUE rb_w32_conv_from_wchar(const WCHAR *wstr, rb_encoding *enc);
|
|
625
627
|
* Returns system configuration directory.
|
626
628
|
*
|
627
629
|
* This is typically "/etc", but is modified by the prefix used when Ruby was
|
628
|
-
* compiled. For example, if Ruby is built and installed in /usr/local,
|
629
|
-
* "/usr/local/etc".
|
630
|
+
* compiled. For example, if Ruby is built and installed in /usr/local,
|
631
|
+
* returns "/usr/local/etc" on other platforms than Windows.
|
632
|
+
* On Windows, this always returns the directory provided by the system.
|
630
633
|
*/
|
631
634
|
static VALUE
|
632
635
|
etc_sysconfdir(VALUE obj)
|
@@ -1012,7 +1015,7 @@ etc_nprocessors(VALUE obj)
|
|
1012
1015
|
|
1013
1016
|
ncpus = etc_nprocessors_affin();
|
1014
1017
|
if (ncpus != -1) {
|
1015
|
-
|
1018
|
+
return INT2NUM(ncpus);
|
1016
1019
|
}
|
1017
1020
|
/* fallback to _SC_NPROCESSORS_ONLN */
|
1018
1021
|
#endif
|
data/ext/etc/extconf.rb
CHANGED
@@ -12,8 +12,10 @@ have_func("uname((struct utsname *)NULL)", headers)
|
|
12
12
|
have_func("getlogin")
|
13
13
|
have_func("getpwent")
|
14
14
|
have_func("getgrent")
|
15
|
-
sysconfdir = RbConfig
|
16
|
-
|
15
|
+
if (sysconfdir = RbConfig::CONFIG["sysconfdir"] and
|
16
|
+
!RbConfig.expand(sysconfdir.dup, "prefix"=>"", "DESTDIR"=>"").empty?)
|
17
|
+
$defs.push("-DSYSCONFDIR=#{Shellwords.escape(sysconfdir.dump)}")
|
18
|
+
end
|
17
19
|
|
18
20
|
have_func("sysconf")
|
19
21
|
have_func("confstr")
|
data/test/etc/test_etc.rb
CHANGED
@@ -97,12 +97,12 @@ class TestEtc < Test::Unit::TestCase
|
|
97
97
|
end
|
98
98
|
|
99
99
|
def test_getgrnam
|
100
|
-
groups = {}
|
100
|
+
groups = Hash.new {[]}
|
101
101
|
Etc.group do |s|
|
102
|
-
groups[s.name]
|
102
|
+
groups[s.name] |= [s.gid] unless /\A\+/ =~ s.name
|
103
103
|
end
|
104
104
|
groups.each_pair do |n, s|
|
105
|
-
|
105
|
+
assert_include(s, Etc.getgrnam(n).gid)
|
106
106
|
end
|
107
107
|
end
|
108
108
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: etc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yukihiro Matsumoto
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -99,7 +99,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
99
99
|
requirements:
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
|
-
version: 2.
|
102
|
+
version: 2.3.0
|
103
103
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
104
104
|
requirements:
|
105
105
|
- - ">="
|
@@ -107,7 +107,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
107
107
|
version: '0'
|
108
108
|
requirements: []
|
109
109
|
rubyforge_project:
|
110
|
-
rubygems_version: 2.
|
110
|
+
rubygems_version: 2.7.3
|
111
111
|
signing_key:
|
112
112
|
specification_version: 4
|
113
113
|
summary: Provides access to information typically stored in UNIX /etc directory.
|