rpam2 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3993568d5198bd46c28c85e10476a0b6be74a563
4
+ data.tar.gz: cd5b593c7e20a494cfea945ac710474453f6552c
5
+ SHA512:
6
+ metadata.gz: 8de8bb0aededc24702641b3c7f2274104a6289f4156511afd3bf86d52ac68847d8a89822cf9d3b8f479ca4644b498725c2a3520e12eeea3ab6483ad6b3f3229e
7
+ data.tar.gz: 86fa80bb39258d1a9c64e777af165cd921b5766c9456f34452baefc536bfa46e8c5f142ce55abdd2b5281198b8b98a0a490a8fbf83aabe5a957e811eac974fed
data/LICENSE.txt ADDED
@@ -0,0 +1,7 @@
1
+ Copyright (c) 2017 Alexander K.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,41 @@
1
+ = rpam2
2
+
3
+ * http://rubyforge.org/projects/rpam2
4
+
5
+ == DESCRIPTION:
6
+
7
+ This extension provides a PAM (Pluggable Authentication Modules)
8
+ integration to ruby. It is inspired by rpam but provides a configurable
9
+ servicename and is licensed under MIT.
10
+
11
+ == EXAMPLE:
12
+
13
+ require 'rpam2'
14
+
15
+ if authpam("servicename", "user", "password")
16
+ puts "Authentication successful"
17
+ else
18
+ puts "Authentication failed"
19
+ end
20
+
21
+ == REQUIREMENTS:
22
+
23
+ * pam-dev
24
+ * ruby-dev
25
+
26
+ == INSTALL:
27
+
28
+ * gem install rpam2
29
+
30
+ Or manually:
31
+
32
+ * gem build rpam2.gemspec
33
+ * gem install ./rpam2-2.0.0.gem
34
+
35
+ == Usage:
36
+
37
+ require 'rpam2'
38
+
39
+ Rpam2.authpam("servicename", "username", "password")
40
+
41
+ Rpam2.accountpam("servicename", "username")
@@ -0,0 +1,17 @@
1
+ require 'mkmf'
2
+
3
+ abort "missing pam library" unless have_library("pam","pam_start")
4
+ abort "missing pam library headers" unless have_header("security/pam_appl.h")
5
+ abort "missing pam library headers" unless have_header("security/pam_modules.h")
6
+
7
+ have_func("pam_end")
8
+ have_func("pam_open_session")
9
+ have_func("pam_close_session")
10
+ have_func("pam_authenticate")
11
+ have_func("pam_acct_mgmt")
12
+ have_func("pam_chauthtok")
13
+ have_func("pam_set_item")
14
+ have_func("pam_get_item")
15
+
16
+
17
+ create_makefile("rpam2/rpam2")
data/ext/rpam2/rpam2.c ADDED
@@ -0,0 +1,134 @@
1
+ #include "ruby.h"
2
+ #include <security/pam_appl.h>
3
+
4
+ static const char *const
5
+ rpam_default_servicename = "rpam";
6
+
7
+ struct auth_wrapper{
8
+ char* pw;
9
+ };
10
+
11
+ static VALUE
12
+ method_authpam(VALUE self, VALUE servicename, VALUE username, VALUE password);
13
+
14
+ static VALUE
15
+ method_accountpam(VALUE self, VALUE servicename, VALUE username);
16
+
17
+ VALUE rpam2;
18
+ void Init_rpam2(){
19
+ rpam2 = rb_define_module("Rpam2");
20
+ rb_define_singleton_method(rpam2, "authpam", method_authpam, 3);
21
+ rb_define_singleton_method(rpam2, "accountpam", method_accountpam, 2);
22
+ }
23
+
24
+ int rpam_auth_conversation(int num_msg, const struct pam_message **msgm,
25
+ struct pam_response **resp, void *appdata_ptr){
26
+ struct pam_response *responses = calloc(num_msg, sizeof(struct pam_response));
27
+ // no space for responses
28
+ if (!responses)
29
+ return PAM_BUF_ERR;
30
+ struct auth_wrapper *authw = (struct auth_wrapper *)appdata_ptr;
31
+ for (int msgc=0; msgc<num_msg; msgc++){
32
+ switch (msgm[msgc]->msg_style) {
33
+ case PAM_PROMPT_ECHO_OFF:
34
+ // Assume ECHO_OFF is password/secret input
35
+ responses[msgc].resp = strdup(authw->pw);
36
+ break;
37
+ case PAM_PROMPT_ECHO_ON:
38
+ case PAM_TEXT_INFO:
39
+ // ignore, they should not occur but some verbose applications exist always
40
+ responses[msgc].resp = strdup("");
41
+ break;
42
+ case PAM_ERROR_MSG:
43
+ // print error message
44
+ rb_warn("%s", msgm[msgc]->msg);
45
+ responses[msgc].resp = strdup("");
46
+ break;
47
+ default:
48
+ free(responses);
49
+ return PAM_CONV_ERR;
50
+ }
51
+ // response could not be allocated (no space)
52
+ if(responses[msgc].resp==0){
53
+ free(responses);
54
+ return PAM_BUF_ERR;
55
+ }
56
+ }
57
+ *resp = responses;
58
+ return PAM_SUCCESS;
59
+ }
60
+
61
+ static VALUE method_authpam(VALUE self, VALUE servicename, VALUE username, VALUE password) {
62
+ pam_handle_t* pamh = NULL;
63
+ unsigned int result=0;
64
+ Check_Type(username, T_STRING);
65
+ Check_Type(password, T_STRING);
66
+
67
+ char *service = rpam_default_servicename;
68
+ if(!NIL_P(servicename)){
69
+ service = StringValueCStr(servicename);
70
+ }
71
+
72
+ struct pam_conv auth_c;
73
+ auth_c.conv = rpam_auth_conversation;
74
+
75
+ struct auth_wrapper authw;
76
+ authw.pw = StringValueCStr(password);
77
+ auth_c.appdata_ptr = &authw;
78
+
79
+ pam_start(service, StringValueCStr(username), &auth_c, &pamh);
80
+ if (result != PAM_SUCCESS) {
81
+ rb_warn("INIT: %s", pam_strerror(pamh, result));
82
+ return Qfalse;
83
+ }
84
+
85
+ result = pam_authenticate(pamh, 0);
86
+ if (result != PAM_SUCCESS) {
87
+ pam_end(pamh, result);
88
+ return Qfalse;
89
+ }
90
+
91
+ result = pam_acct_mgmt(pamh, 0);
92
+ if (result != PAM_SUCCESS) {
93
+ pam_end(pamh, result);
94
+ return Qfalse;
95
+ }
96
+
97
+ if (pam_end(pamh, result) == PAM_SUCCESS)
98
+ return Qtrue;
99
+ else {
100
+ rb_warn("END: %s", pam_strerror(pamh, result));
101
+ return Qfalse;
102
+ }
103
+ }
104
+
105
+ static VALUE method_accountpam(VALUE self, VALUE servicename, VALUE username) {
106
+ pam_handle_t* pamh = NULL;
107
+ unsigned int result=0;
108
+ Check_Type(username, T_STRING);
109
+
110
+ char *service = rpam_default_servicename;
111
+ if(!NIL_P(servicename)){
112
+ service = StringValueCStr(servicename);
113
+ }
114
+
115
+ struct pam_conv auth_c = {0,0};
116
+ pam_start(service, StringValueCStr(username), &auth_c, &pamh);
117
+ if (result != PAM_SUCCESS) {
118
+ rb_warn("INIT: %s", pam_strerror(pamh, result));
119
+ return Qfalse;
120
+ }
121
+
122
+ result = pam_acct_mgmt(pamh, 0);
123
+ if (result != PAM_SUCCESS) {
124
+ pam_end(pamh, result);
125
+ return Qfalse;
126
+ }
127
+
128
+ if (pam_end(pamh, result) == PAM_SUCCESS)
129
+ return Qtrue;
130
+ else {
131
+ rb_warn("END: %s", pam_strerror(pamh, result));
132
+ return Qfalse;
133
+ }
134
+ }
data/lib/rpam2.rb ADDED
@@ -0,0 +1,5 @@
1
+ module Rpam2
2
+ VERSION = 2.0
3
+ end
4
+
5
+ require "rpam2/rpam2"
data/rpam2.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rpam2"
3
+ s.version = "2.0.0"
4
+ s.date = "2017-09-27"
5
+ s.summary = "PAM integration with ruby."
6
+ s.email = "devkral@web.de"
7
+ s.description = "Ruby PAM (Pluggable Authentication
8
+ Modules) integration"
9
+ s.extra_rdoc_files = ["README.rdoc"]
10
+ s.authors = ["Alexander Kaftan"]
11
+ s.files = ["lib/rpam2.rb", "ext/rpam2/rpam2.c", "ext/rpam2/extconf.rb", "rpam2.gemspec", "README.rdoc", "LICENSE.txt"]
12
+ s.has_rdoc = true
13
+ s.license = "MIT"
14
+ s.homepage = "http://github.com/devkral/rpam2"
15
+ s.require_paths = ["lib"]
16
+ s.extensions = ["ext/rpam2/extconf.rb"]
17
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rpam2
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Kaftan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-27 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |-
14
+ Ruby PAM (Pluggable Authentication
15
+ Modules) integration
16
+ email: devkral@web.de
17
+ executables: []
18
+ extensions:
19
+ - ext/rpam2/extconf.rb
20
+ extra_rdoc_files:
21
+ - README.rdoc
22
+ files:
23
+ - LICENSE.txt
24
+ - README.rdoc
25
+ - ext/rpam2/extconf.rb
26
+ - ext/rpam2/rpam2.c
27
+ - lib/rpam2.rb
28
+ - rpam2.gemspec
29
+ homepage: http://github.com/devkral/rpam2
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.6.13
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: PAM integration with ruby.
53
+ test_files: []