rpam2 3.0.2 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +11 -5
- data/ext/rpam2/rpam2.c +88 -100
- data/lib/rpam2.rb +37 -0
- data/rpam2.gemspec +2 -3
- metadata +2 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8180810fbc2a5e9a9ac2eeac16e0a62bff594e6c
|
4
|
+
data.tar.gz: d43a52c9d4e266a1a91bebceb057f29d955da4f3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f7172cb9bc9cb1a78c052d75f3663d430b222c5bd70c33bcb762e5a171899fb250eff5e0bb8a4404bb2647cb0dbfb0da24cc8d9d6739f7c8985e1511d3260588
|
7
|
+
data.tar.gz: d14f701064970ddea61f52ab036fbfc86a7a030aa3a614d2b8a27c4e3c7e66d822b8a3985f11fe5dedd1a066f20c09dea81f71a5bb730f858d541d733551dcae
|
data/README.rdoc
CHANGED
@@ -5,8 +5,8 @@
|
|
5
5
|
== DESCRIPTION:
|
6
6
|
|
7
7
|
This extension provides a PAM (Pluggable Authentication Modules)
|
8
|
-
integration to ruby. It is inspired by rpam but provides
|
9
|
-
|
8
|
+
integration to ruby. It is inspired by rpam but provides much functionality
|
9
|
+
and is licensed under MIT.
|
10
10
|
|
11
11
|
== EXAMPLE:
|
12
12
|
|
@@ -17,6 +17,12 @@
|
|
17
17
|
else
|
18
18
|
puts "Authentication failed"
|
19
19
|
end
|
20
|
+
|
21
|
+
puts Rpam2.listenv(nil, "user", "password") # uses default (rpam)
|
22
|
+
puts Rpam2.listenv("servicename", "user", "password")
|
23
|
+
puts Rpam2.listenv("servicename", "user", "password", true)
|
24
|
+
puts Rpam2.listenv("servicename", "user", "password", true, "RUSER", "RHOST")
|
25
|
+
puts Rpam2.listenv("servicename") # error
|
20
26
|
|
21
27
|
== REQUIREMENTS:
|
22
28
|
|
@@ -36,10 +42,10 @@ Or manually:
|
|
36
42
|
|
37
43
|
require 'rpam2'
|
38
44
|
|
39
|
-
Rpam2.auth("servicename", "username", "password") => (true/false)
|
45
|
+
Rpam2.auth("servicename", "username", "password", ["RUSER", "RHOST"]) => (true/false)
|
40
46
|
|
41
47
|
Rpam2.account("servicename", "username") => (true/false)
|
42
48
|
|
43
|
-
Rpam2.getenv("servicename", "username", "password", "envvar",
|
49
|
+
Rpam2.getenv("servicename", "username", "password", "envvar", [opensession(true/false), ["RUSER", "RHOST"]]) => (string/nil)
|
44
50
|
|
45
|
-
Rpam2.listenv("servicename", "username", "password",
|
51
|
+
Rpam2.listenv("servicename", "username", "password", [opensession(true/false), ["RUSER", "RHOST"]]) => (hash/nil)
|
data/ext/rpam2/rpam2.c
CHANGED
@@ -9,27 +9,7 @@ struct auth_wrapper{
|
|
9
9
|
char* pw;
|
10
10
|
};
|
11
11
|
|
12
|
-
static VALUE
|
13
|
-
method_authpam(VALUE self, VALUE servicename, VALUE username, VALUE password);
|
14
|
-
|
15
|
-
static VALUE
|
16
|
-
method_accountpam(VALUE self, VALUE servicename, VALUE username);
|
17
|
-
|
18
|
-
static VALUE
|
19
|
-
method_getenvpam(VALUE self, VALUE servicename, VALUE username, VALUE password, VALUE envname, VALUE opensession);
|
20
|
-
|
21
|
-
static VALUE
|
22
|
-
method_listenvpam(VALUE self, VALUE servicename, VALUE username, VALUE password, VALUE opensession);
|
23
|
-
|
24
|
-
|
25
12
|
VALUE rpam2;
|
26
|
-
void Init_rpam2(){
|
27
|
-
rpam2 = rb_define_module("Rpam2");
|
28
|
-
rb_define_singleton_method(rpam2, "auth", method_authpam, 3);
|
29
|
-
rb_define_singleton_method(rpam2, "account", method_accountpam, 2);
|
30
|
-
rb_define_singleton_method(rpam2, "getenv", method_getenvpam, 5);
|
31
|
-
rb_define_singleton_method(rpam2, "listenv", method_listenvpam, 4);
|
32
|
-
}
|
33
13
|
|
34
14
|
int rpam_auth_conversation(int num_msg, const struct pam_message **msgm,
|
35
15
|
struct pam_response **resp, void *appdata_ptr){
|
@@ -68,45 +48,82 @@ int rpam_auth_conversation(int num_msg, const struct pam_message **msgm,
|
|
68
48
|
return PAM_SUCCESS;
|
69
49
|
}
|
70
50
|
|
71
|
-
|
72
|
-
|
73
|
-
unsigned int result = 0;
|
51
|
+
// password as char* ensures that no Qnil can be used
|
52
|
+
static unsigned int _start(pam_handle_t* pamh, VALUE* service, char* password, VALUE *RUSER, VALUE* RHOST){
|
74
53
|
struct pam_conv auth_c;
|
75
54
|
struct auth_wrapper authw;
|
76
|
-
|
55
|
+
unsigned int result = 0;
|
77
56
|
|
78
|
-
|
79
|
-
|
57
|
+
if(service && !NIL_P(*service)){
|
58
|
+
result = pam_set_item(pamh, PAM_SERVICE, StringValueCStr(*service));
|
80
59
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
service = rpam_default_servicename;
|
60
|
+
if (result != PAM_SUCCESS) {
|
61
|
+
rb_warn("SET SERVICE: %s", pam_strerror(pamh, result));
|
62
|
+
return result;
|
63
|
+
}
|
86
64
|
}
|
87
65
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
66
|
+
if(RUSER && !NIL_P(*RUSER)){
|
67
|
+
result = pam_set_item(pamh, PAM_RUSER, StringValueCStr(*RUSER));
|
68
|
+
if (result != PAM_SUCCESS) {
|
69
|
+
rb_warn("SET RUSER: %s", pam_strerror(pamh, result));
|
70
|
+
return result;
|
71
|
+
}
|
72
|
+
}
|
92
73
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
74
|
+
if(RHOST && !NIL_P(*RHOST)){
|
75
|
+
result = pam_set_item(pamh, PAM_RHOST, StringValueCStr(*RHOST));
|
76
|
+
if (result != PAM_SUCCESS) {
|
77
|
+
rb_warn("SET RHOST: %s", pam_strerror(pamh, result));
|
78
|
+
return result;
|
79
|
+
}
|
97
80
|
}
|
98
81
|
|
99
82
|
result = pam_acct_mgmt(pamh, 0);
|
100
83
|
if (result != PAM_SUCCESS) {
|
101
84
|
pam_end(pamh, result);
|
102
|
-
return
|
85
|
+
return result;
|
86
|
+
}
|
87
|
+
|
88
|
+
if(password){
|
89
|
+
// cannot set token as item (except implementing some special methods) so use a conversation
|
90
|
+
auth_c.conv = rpam_auth_conversation;
|
91
|
+
authw.pw = password;
|
92
|
+
auth_c.appdata_ptr = &authw;
|
93
|
+
|
94
|
+
result = pam_set_item(pamh, PAM_CONV, &auth_c);
|
95
|
+
if (result != PAM_SUCCESS) {
|
96
|
+
rb_warn("SET CONV: %s", pam_strerror(pamh, result));
|
97
|
+
return result;
|
98
|
+
}
|
99
|
+
result = pam_authenticate(pamh, 0);
|
100
|
+
if (result != PAM_SUCCESS) {
|
101
|
+
pam_end(pamh, result);
|
102
|
+
return result;
|
103
|
+
}
|
103
104
|
}
|
105
|
+
return result;
|
106
|
+
}
|
104
107
|
|
105
|
-
|
108
|
+
|
109
|
+
static VALUE method_authpam(VALUE self, VALUE servicename, VALUE username, VALUE password, VALUE ruser, VALUE rhost) {
|
110
|
+
pam_handle_t* pamh = NULL;
|
111
|
+
unsigned int result = 0;
|
112
|
+
struct pam_conv auth_c = {0,0};
|
113
|
+
|
114
|
+
Check_Type(username, T_STRING);
|
115
|
+
Check_Type(password, T_STRING);
|
116
|
+
|
117
|
+
result = pam_start(rpam_default_servicename, StringValueCStr(username), &auth_c, &pamh);
|
106
118
|
if (result != PAM_SUCCESS) {
|
107
|
-
|
119
|
+
rb_warn("INIT: %s", pam_strerror(pamh, result));
|
108
120
|
return Qfalse;
|
109
121
|
}
|
122
|
+
|
123
|
+
result = _start(pamh, &servicename, StringValueCStr(password), &ruser, &rhost);
|
124
|
+
if(result!=PAM_SUCCESS)
|
125
|
+
return Qfalse;
|
126
|
+
|
110
127
|
|
111
128
|
if (pam_end(pamh, result) == PAM_SUCCESS)
|
112
129
|
return Qtrue;
|
@@ -116,32 +133,23 @@ static VALUE method_authpam(VALUE self, VALUE servicename, VALUE username, VALUE
|
|
116
133
|
}
|
117
134
|
}
|
118
135
|
|
136
|
+
|
119
137
|
static VALUE method_accountpam(VALUE self, VALUE servicename, VALUE username) {
|
120
138
|
pam_handle_t* pamh = NULL;
|
121
139
|
unsigned int result=0;
|
122
140
|
struct pam_conv auth_c = {0,0};
|
123
|
-
const char *service;
|
124
|
-
|
125
|
-
Check_Type(username, T_STRING);
|
126
|
-
|
127
141
|
|
128
|
-
|
129
|
-
service = StringValueCStr(servicename);
|
130
|
-
} else {
|
131
|
-
service = rpam_default_servicename;
|
132
|
-
}
|
142
|
+
Check_Type(username, T_STRING);
|
133
143
|
|
134
|
-
pam_start(
|
144
|
+
result = pam_start(rpam_default_servicename, StringValueCStr(username), &auth_c, &pamh);
|
135
145
|
if (result != PAM_SUCCESS) {
|
136
146
|
rb_warn("INIT: %s", pam_strerror(pamh, result));
|
137
147
|
return Qfalse;
|
138
148
|
}
|
139
149
|
|
140
|
-
result =
|
141
|
-
if
|
142
|
-
pam_end(pamh, result);
|
150
|
+
result = _start(pamh, &servicename, NULL, NULL, NULL);
|
151
|
+
if(result!=PAM_SUCCESS)
|
143
152
|
return Qfalse;
|
144
|
-
}
|
145
153
|
|
146
154
|
if (pam_end(pamh, result) == PAM_SUCCESS)
|
147
155
|
return Qtrue;
|
@@ -152,42 +160,26 @@ static VALUE method_accountpam(VALUE self, VALUE servicename, VALUE username) {
|
|
152
160
|
}
|
153
161
|
|
154
162
|
|
155
|
-
static VALUE method_getenvpam(VALUE self, VALUE servicename, VALUE username, VALUE password, VALUE envname, VALUE opensession) {
|
163
|
+
static VALUE method_getenvpam(VALUE self, VALUE servicename, VALUE username, VALUE password, VALUE envname, VALUE opensession, VALUE ruser, VALUE rhost) {
|
156
164
|
pam_handle_t* pamh = NULL;
|
157
|
-
unsigned int result=0;
|
158
|
-
struct pam_conv auth_c;
|
159
|
-
struct auth_wrapper authw;
|
160
|
-
const char *service;
|
161
165
|
const char *c_ret;
|
162
166
|
VALUE ruby_ret;
|
163
|
-
|
167
|
+
unsigned int result = 0;
|
168
|
+
struct pam_conv auth_c = {0,0};
|
169
|
+
|
164
170
|
Check_Type(username, T_STRING);
|
165
171
|
Check_Type(password, T_STRING);
|
166
172
|
Check_Type(envname, T_STRING);
|
167
173
|
|
168
|
-
|
169
|
-
if(!NIL_P(servicename)){
|
170
|
-
service = StringValueCStr(servicename);
|
171
|
-
} else {
|
172
|
-
service = rpam_default_servicename;
|
173
|
-
}
|
174
|
-
|
175
|
-
auth_c.conv = rpam_auth_conversation;
|
176
|
-
|
177
|
-
authw.pw = StringValueCStr(password);
|
178
|
-
auth_c.appdata_ptr = &authw;
|
179
|
-
|
180
|
-
pam_start(service, StringValueCStr(username), &auth_c, &pamh);
|
174
|
+
result = pam_start(rpam_default_servicename, StringValueCStr(username), &auth_c, &pamh);
|
181
175
|
if (result != PAM_SUCCESS) {
|
182
176
|
rb_warn("INIT: %s", pam_strerror(pamh, result));
|
183
177
|
return Qnil;
|
184
178
|
}
|
185
|
-
|
186
|
-
result =
|
187
|
-
if
|
188
|
-
pam_end(pamh, result);
|
179
|
+
|
180
|
+
result = _start(pamh, &servicename, StringValueCStr(password), &ruser, &rhost);
|
181
|
+
if(result != PAM_SUCCESS)
|
189
182
|
return Qnil;
|
190
|
-
}
|
191
183
|
|
192
184
|
if (RTEST(opensession)){
|
193
185
|
result = pam_open_session(pamh, 0);
|
@@ -218,42 +210,29 @@ static VALUE method_getenvpam(VALUE self, VALUE servicename, VALUE username, VAL
|
|
218
210
|
return ruby_ret;
|
219
211
|
}
|
220
212
|
|
221
|
-
|
213
|
+
|
214
|
+
static VALUE method_listenvpam(VALUE self, VALUE servicename, VALUE username, VALUE password, VALUE opensession, VALUE ruser, VALUE rhost){
|
222
215
|
pam_handle_t* pamh = NULL;
|
223
216
|
unsigned int result=0;
|
224
|
-
struct pam_conv auth_c;
|
225
|
-
struct auth_wrapper authw;
|
226
217
|
char *last;
|
227
|
-
const char *service;
|
228
218
|
char **envlist;
|
229
219
|
char **tmpenvlist;
|
230
220
|
VALUE ruby_ret;
|
221
|
+
struct pam_conv auth_c = {0,0};
|
231
222
|
|
232
223
|
Check_Type(username, T_STRING);
|
233
224
|
Check_Type(password, T_STRING);
|
234
225
|
|
235
226
|
|
236
|
-
|
237
|
-
service = StringValueCStr(servicename);
|
238
|
-
} else {
|
239
|
-
service = rpam_default_servicename;
|
240
|
-
}
|
241
|
-
|
242
|
-
auth_c.conv = rpam_auth_conversation;
|
243
|
-
authw.pw = StringValueCStr(password);
|
244
|
-
auth_c.appdata_ptr = &authw;
|
245
|
-
|
246
|
-
pam_start(service, StringValueCStr(username), &auth_c, &pamh);
|
227
|
+
result = pam_start(rpam_default_servicename, StringValueCStr(username), &auth_c, &pamh);
|
247
228
|
if (result != PAM_SUCCESS) {
|
248
229
|
rb_warn("INIT: %s", pam_strerror(pamh, result));
|
249
230
|
return Qnil;
|
250
231
|
}
|
251
|
-
|
252
|
-
result =
|
253
|
-
if
|
254
|
-
pam_end(pamh, result);
|
232
|
+
|
233
|
+
result = _start(pamh, &servicename, StringValueCStr(password), &ruser, &rhost);
|
234
|
+
if(result != PAM_SUCCESS)
|
255
235
|
return Qnil;
|
256
|
-
}
|
257
236
|
|
258
237
|
if (RTEST(opensession)){
|
259
238
|
result = pam_open_session(pamh, 0);
|
@@ -296,3 +275,12 @@ static VALUE method_listenvpam(VALUE self, VALUE servicename, VALUE username, VA
|
|
296
275
|
return ruby_ret;
|
297
276
|
}
|
298
277
|
|
278
|
+
|
279
|
+
void Init_rpam2(){
|
280
|
+
rpam2 = rb_define_module("Rpam2");
|
281
|
+
rb_define_singleton_method(rpam2, "_auth", method_authpam, 5);
|
282
|
+
rb_define_singleton_method(rpam2, "account", method_accountpam, 2);
|
283
|
+
rb_define_singleton_method(rpam2, "_getenv", method_getenvpam, 7);
|
284
|
+
rb_define_singleton_method(rpam2, "_listenv", method_listenvpam, 6);
|
285
|
+
}
|
286
|
+
|
data/lib/rpam2.rb
CHANGED
@@ -1,5 +1,42 @@
|
|
1
1
|
module Rpam2
|
2
2
|
VERSION = 2.0
|
3
|
+
class << self
|
4
|
+
def auth(*args)
|
5
|
+
case args.size
|
6
|
+
when 3
|
7
|
+
self._auth(*args, nil, nil)
|
8
|
+
when 5
|
9
|
+
self._auth(*args)
|
10
|
+
else
|
11
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 3 or 5)"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
def getenv(*args)
|
15
|
+
case args.size
|
16
|
+
when 4
|
17
|
+
self._getenv(*args, nil, nil, nil)
|
18
|
+
when 5
|
19
|
+
self._getenv(*args, nil, nil)
|
20
|
+
when 7
|
21
|
+
self._getenv(*args)
|
22
|
+
else
|
23
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 4, 5 or 7)"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def listenv(*args)
|
28
|
+
case args.size
|
29
|
+
when 3
|
30
|
+
self._listenv(*args, nil, nil, nil)
|
31
|
+
when 4
|
32
|
+
self._listenv(*args, nil, nil)
|
33
|
+
when 6
|
34
|
+
self._listenv(*args)
|
35
|
+
else
|
36
|
+
raise ArgumentError, "wrong number of arguments (given #{args.size}, expected 3, 4 or 6)"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
3
40
|
end
|
4
41
|
|
5
42
|
require "rpam2/rpam2"
|
data/rpam2.gemspec
CHANGED
@@ -1,11 +1,10 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "rpam2"
|
3
|
-
s.version = "3.0
|
3
|
+
s.version = "3.1.0"
|
4
4
|
s.date = "2017-10-10"
|
5
5
|
s.summary = "PAM integration with ruby."
|
6
6
|
s.email = "devkral@web.de"
|
7
|
-
s.description = "Ruby PAM (Pluggable Authentication
|
8
|
-
Modules) integration"
|
7
|
+
s.description = "Ruby PAM (Pluggable Authentication Modules) integration"
|
9
8
|
s.extra_rdoc_files = ["README.rdoc"]
|
10
9
|
s.authors = ["Alexander Kaftan"]
|
11
10
|
s.files = ["lib/rpam2.rb", "ext/rpam2/rpam2.c", "ext/rpam2/extconf.rb", "rpam2.gemspec", "README.rdoc", "LICENSE.txt"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rpam2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0
|
4
|
+
version: 3.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexander Kaftan
|
@@ -10,9 +10,7 @@ bindir: bin
|
|
10
10
|
cert_chain: []
|
11
11
|
date: 2017-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description:
|
14
|
-
Ruby PAM (Pluggable Authentication
|
15
|
-
Modules) integration
|
13
|
+
description: Ruby PAM (Pluggable Authentication Modules) integration
|
16
14
|
email: devkral@web.de
|
17
15
|
executables: []
|
18
16
|
extensions:
|