netsoul 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -1
- data/README.md +5 -9
- data/bin/netsoul-ruby +36 -35
- data/ext/netsoul_kerberos/kerberos.c +107 -107
- data/ext/netsoul_kerberos/kerberos.h +9 -9
- data/ext/netsoul_kerberos/netsoul_kerberos.c +11 -9
- data/lib/netsoul/location.rb +1 -5
- data/lib/netsoul/message.rb +11 -6
- data/lib/netsoul/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7c87d6edb74b1dd1b82b6617944658c472f8ceff
|
4
|
+
data.tar.gz: 705d281ad0c3174ad5aadbfc9dbaa367e14dae8e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2facc495620c54c44ef89d081ce5a2e3794f39937ff96887af617a330907a42144ffb90d4f5a2c8b731332e9679bdba4c44e516bc9cdbe88f1b5037b7738b1c3
|
7
|
+
data.tar.gz: 3537edb9e19b2dd4048d9c744f7dd7728d8bf8bee601d514352c8124e7c80ec1c8401859cfa40c57b685509981dbf99f04ff2c726301420d189a4e0e46e15d71
|
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Netsoul-Ruby [](http://badge.fury.io/rb/netsoul) [](https://travis-ci.org/fenicks/netsoul-ruby) [](https://coveralls.io/github/fenicks/netsoul-ruby?branch=master)
|
2
2
|
|
3
3
|
* formerly __libnetsoul-rb__
|
4
4
|
|
@@ -19,21 +19,17 @@ You can use it as a Ruby gem in order to implement your own Netsoul client in Ru
|
|
19
19
|
|
20
20
|
### On your desktop
|
21
21
|
|
22
|
-
```bash
|
23
22
|
gem install netsoul
|
24
|
-
```
|
25
23
|
|
26
24
|
### In your project
|
27
25
|
|
28
|
-
|
29
|
-
|
26
|
+
#### Gemfile
|
27
|
+
|
30
28
|
gem 'netsoul', '~> 0.1'
|
31
|
-
```
|
32
29
|
|
33
|
-
|
34
|
-
|
30
|
+
#### project.rb
|
31
|
+
|
35
32
|
require 'netsoul'
|
36
|
-
```
|
37
33
|
|
38
34
|
## Use the client
|
39
35
|
|
data/bin/netsoul-ruby
CHANGED
@@ -3,11 +3,11 @@
|
|
3
3
|
lib = File.expand_path('../../lib', __FILE__)
|
4
4
|
$LOAD_PATH.unshift lib unless $LOAD_PATH.include?(lib)
|
5
5
|
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require 'netsoul'
|
6
|
+
require 'netsoul/config'
|
7
|
+
require 'netsoul/errors'
|
8
|
+
require 'netsoul/logging'
|
9
|
+
require 'netsoul/message'
|
9
10
|
require 'socket'
|
10
|
-
require 'uri'
|
11
11
|
|
12
12
|
module Netsoul
|
13
13
|
class Client
|
@@ -82,41 +82,42 @@ module Netsoul
|
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
end
|
100
|
-
options[:user_opts] = YAML.load_file(options[:config])
|
101
|
-
end
|
102
|
-
opts.on('-h', '--help', 'Display this screen') do
|
103
|
-
puts opts
|
85
|
+
$stderr.sync = true
|
86
|
+
require 'optparse'
|
87
|
+
require 'yaml'
|
88
|
+
|
89
|
+
options = {}
|
90
|
+
OptionParser.new do |opts|
|
91
|
+
opts.banner = 'Usage: netsoul-ruby [options]'.freeze
|
92
|
+
opts.separator ''.freeze
|
93
|
+
opts.separator 'Netsoul-Ruby options:'.freeze
|
94
|
+
|
95
|
+
opts.on('-c'.freeze, '--config FILE'.freeze, 'Configuration file in YAML'.freeze) do |file|
|
96
|
+
options[:config] = file
|
97
|
+
unless File.file?(options[:config])
|
98
|
+
puts '[ERROR] Configuration is not a valid file'
|
104
99
|
exit
|
105
100
|
end
|
106
|
-
|
101
|
+
options[:user_opts] = YAML.load_file(options[:config])
|
102
|
+
end
|
107
103
|
|
108
|
-
|
109
|
-
puts
|
104
|
+
opts.on('-h', '--help', 'Display this screen') do
|
105
|
+
puts opts
|
110
106
|
exit
|
111
107
|
end
|
108
|
+
end.parse!
|
112
109
|
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
110
|
+
unless options.include?(:config)
|
111
|
+
puts '[ERROR] Configuration file is not provided'
|
112
|
+
exit
|
113
|
+
end
|
114
|
+
|
115
|
+
c = Netsoul::Client.new options[:user_opts]
|
116
|
+
c.connect
|
117
|
+
if c.started
|
118
|
+
loop do
|
119
|
+
res = c.sock_get
|
120
|
+
c.sock_send res if res.to_s.match(/^ping.*/)
|
121
|
+
sleep 1
|
121
122
|
end
|
122
|
-
|
123
|
+
end
|
@@ -17,22 +17,22 @@
|
|
17
17
|
|
18
18
|
void display_status(k_data_t *data)
|
19
19
|
{
|
20
|
-
|
21
|
-
|
20
|
+
OM_uint32 minor, status;
|
21
|
+
gss_buffer_desc msg;
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
gss_display_status(&minor, data->min, GSS_C_GSS_CODE, GSS_C_NO_OID, &status, &msg);
|
24
|
+
if (msg.value) puts(msg.value);
|
25
25
|
}
|
26
26
|
|
27
|
-
krb5_error_code get_new_tickets(
|
28
|
-
|
29
|
-
|
30
|
-
|
27
|
+
krb5_error_code get_new_tickets(k_data_t *data,
|
28
|
+
krb5_context context,
|
29
|
+
krb5_principal principal,
|
30
|
+
krb5_ccache ccache)
|
31
31
|
{
|
32
|
-
krb5_error_code
|
33
|
-
krb5_get_init_creds_opt
|
34
|
-
krb5_creds
|
35
|
-
// char
|
32
|
+
krb5_error_code ret;
|
33
|
+
krb5_get_init_creds_opt opt;
|
34
|
+
krb5_creds cred;
|
35
|
+
// char *password = NULL;
|
36
36
|
|
37
37
|
memset(&cred, 0, sizeof(cred));
|
38
38
|
krb5_get_init_creds_opt_init (&opt);
|
@@ -55,16 +55,16 @@ krb5_error_code get_new_tickets( k_data_t *data,
|
|
55
55
|
return (3);
|
56
56
|
if (krb5_cc_store_cred(context, ccache, &cred))
|
57
57
|
return (3);
|
58
|
-
//krb5_free_creds_contents(context, &cred);
|
58
|
+
// krb5_free_creds_contents(context, &cred);
|
59
59
|
return (0);
|
60
60
|
}
|
61
61
|
|
62
62
|
int my_init(k_data_t *data)
|
63
63
|
{
|
64
|
-
krb5_error_code
|
65
|
-
krb5_context
|
66
|
-
krb5_ccache
|
67
|
-
krb5_principal
|
64
|
+
krb5_error_code ret;
|
65
|
+
krb5_context context;
|
66
|
+
krb5_ccache ccache;
|
67
|
+
krb5_principal principal;
|
68
68
|
|
69
69
|
if (krb5_init_context(&context))
|
70
70
|
return (1);
|
@@ -84,62 +84,62 @@ int my_init(k_data_t *data)
|
|
84
84
|
|
85
85
|
void import_name(k_data_t *data)
|
86
86
|
{
|
87
|
-
|
88
|
-
|
89
|
-
|
87
|
+
OM_uint32 min;
|
88
|
+
OM_uint32 maj;
|
89
|
+
gss_buffer_desc buf;
|
90
90
|
|
91
|
-
|
92
|
-
|
93
|
-
|
91
|
+
buf.value = (unsigned char *) strdup(NS_SERVICE_NAME);
|
92
|
+
buf.length = strlen((const char*)buf.value) + 1;
|
93
|
+
maj = gss_import_name(&min, &buf, GSS_C_NT_HOSTBASED_SERVICE, &data->gss_name);
|
94
94
|
|
95
|
-
|
96
|
-
|
95
|
+
if (maj != GSS_S_COMPLETE)
|
96
|
+
display_status(data);
|
97
97
|
}
|
98
98
|
|
99
99
|
void init_context(k_data_t *data)
|
100
100
|
{
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
101
|
+
OM_uint32 maj;
|
102
|
+
/* gss_buffer_t itoken = GSS_C_NO_BUFFER; */
|
103
|
+
krb5_enctype etypes[] = { ENCTYPE_DES3_CBC_SHA1, ENCTYPE_NULL };
|
104
|
+
int etype_count = sizeof(etypes) / sizeof(*etypes);
|
105
|
+
gss_cred_id_t credh;
|
106
|
+
|
107
|
+
maj = gss_acquire_cred( &data->min,
|
108
|
+
GSS_C_NO_NAME,
|
109
|
+
GSS_C_INDEFINITE,
|
110
|
+
GSS_C_NO_OID_SET,
|
111
|
+
GSS_C_INITIATE,
|
112
|
+
&credh,
|
113
|
+
NULL,
|
114
|
+
NULL);
|
115
|
+
if (maj != GSS_S_COMPLETE)
|
116
|
+
{
|
117
|
+
display_status(data);
|
118
|
+
return;
|
119
|
+
}
|
120
|
+
maj = gss_krb5_set_allowable_enctypes(&data->min, credh, etype_count, etypes);
|
121
|
+
if (maj != GSS_S_COMPLETE)
|
122
|
+
{
|
123
|
+
display_status(data);
|
124
|
+
return;
|
125
|
+
}
|
126
|
+
data->ctx = GSS_C_NO_CONTEXT;
|
127
|
+
maj = gss_init_sec_context( &data->min,
|
128
|
+
credh,
|
129
|
+
&data->ctx,
|
130
|
+
data->gss_name,
|
131
|
+
GSS_C_NO_OID,
|
132
|
+
GSS_C_CONF_FLAG,
|
133
|
+
0,
|
134
|
+
GSS_C_NO_CHANNEL_BINDINGS,
|
135
|
+
data->itoken,
|
136
|
+
NULL,
|
137
|
+
&data->otoken,
|
138
|
+
NULL,
|
139
|
+
NULL);
|
140
|
+
|
141
|
+
if (data->maj != GSS_S_COMPLETE)
|
142
|
+
display_status(data);
|
143
143
|
}
|
144
144
|
|
145
145
|
int check_tokens(k_data_t *data)
|
@@ -162,45 +162,45 @@ int check_tokens(k_data_t *data)
|
|
162
162
|
/**
|
163
163
|
* Encode string in base64
|
164
164
|
*/
|
165
|
-
unsigned char
|
165
|
+
unsigned char* base64_encode(const unsigned char *src, size_t len, size_t *out_len)
|
166
166
|
{
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
167
|
+
unsigned char *out, *pos;
|
168
|
+
const unsigned char *end, *in;
|
169
|
+
size_t olen;
|
170
|
+
int line_len;
|
171
|
+
const unsigned char base64_table[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
172
|
+
|
173
|
+
olen = len * 4 / 3 + 4; /* 3-byte blocks to 4-byte */
|
174
|
+
out = malloc(olen);
|
175
|
+
if (out == NULL)
|
176
|
+
return NULL;
|
177
|
+
|
178
|
+
end = src + len;
|
179
|
+
in = src;
|
180
|
+
pos = out;
|
181
|
+
while (end - in >= 3) {
|
182
|
+
*pos++ = base64_table[in[0] >> 2];
|
183
|
+
*pos++ = base64_table[((in[0] & 0x03) << 4) | (in[1] >> 4)];
|
184
|
+
*pos++ = base64_table[((in[1] & 0x0f) << 2) | (in[2] >> 6)];
|
185
|
+
*pos++ = base64_table[in[2] & 0x3f];
|
186
|
+
in += 3;
|
187
|
+
}
|
188
|
+
|
189
|
+
if (end - in) {
|
190
|
+
*pos++ = base64_table[in[0] >> 2];
|
191
|
+
if (end - in == 1) {
|
192
|
+
*pos++ = base64_table[(in[0] & 0x03) << 4];
|
193
|
+
*pos++ = '=';
|
194
|
+
} else {
|
195
|
+
*pos++ = base64_table[((in[0] & 0x03) << 4) |
|
196
|
+
(in[1] >> 4)];
|
197
|
+
*pos++ = base64_table[(in[1] & 0x0f) << 2];
|
198
|
+
}
|
199
|
+
*pos++ = '=';
|
200
|
+
line_len += 4;
|
201
|
+
}
|
202
|
+
|
203
|
+
if (out_len)
|
204
|
+
*out_len = pos - out;
|
205
|
+
return out;
|
206
206
|
}
|
@@ -21,11 +21,11 @@
|
|
21
21
|
|
22
22
|
typedef struct k_data
|
23
23
|
{
|
24
|
-
char*
|
25
|
-
char*
|
26
|
-
OM_uint32
|
27
|
-
OM_uint32
|
28
|
-
gss_name_t
|
24
|
+
char* login;
|
25
|
+
char* unix_pass;
|
26
|
+
OM_uint32 min;
|
27
|
+
OM_uint32 maj;
|
28
|
+
gss_name_t gss_name;
|
29
29
|
gss_ctx_id_t ctx;
|
30
30
|
gss_buffer_t itoken;
|
31
31
|
gss_buffer_desc otoken;
|
@@ -35,10 +35,10 @@ void
|
|
35
35
|
display_status(k_data_t *data);
|
36
36
|
|
37
37
|
krb5_error_code
|
38
|
-
get_new_tickets(
|
39
|
-
|
40
|
-
|
41
|
-
|
38
|
+
get_new_tickets(k_data_t *data,
|
39
|
+
krb5_context context,
|
40
|
+
krb5_principal principal,
|
41
|
+
krb5_ccache ccache);
|
42
42
|
|
43
43
|
int
|
44
44
|
my_init(k_data_t *data);
|
@@ -14,26 +14,28 @@ VALUE cNetsoulKerberos;
|
|
14
14
|
|
15
15
|
static VALUE k_init(VALUE self)
|
16
16
|
{
|
17
|
-
rb_define_attr(cNetsoulKerberos, "login",
|
18
|
-
rb_define_attr(cNetsoulKerberos, "password",
|
19
|
-
rb_define_attr(cNetsoulKerberos, "token",
|
17
|
+
rb_define_attr(cNetsoulKerberos, "login", 1, 1);
|
18
|
+
rb_define_attr(cNetsoulKerberos, "password", 1, 1);
|
19
|
+
rb_define_attr(cNetsoulKerberos, "token", 1, 0);
|
20
20
|
rb_define_attr(cNetsoulKerberos, "token_base64", 1, 0);
|
21
21
|
return self;
|
22
22
|
}
|
23
23
|
|
24
24
|
static VALUE k_build_token(VALUE self, VALUE login, VALUE password)
|
25
25
|
{
|
26
|
-
k_data_t
|
27
|
-
unsigned char
|
28
|
-
unsigned char
|
29
|
-
size_t
|
26
|
+
k_data_t *data;
|
27
|
+
unsigned char *token_base64;
|
28
|
+
unsigned char *token;
|
29
|
+
size_t elen;
|
30
30
|
|
31
31
|
data = calloc(1, sizeof (k_data_t));
|
32
32
|
data->login = (char*)login;
|
33
33
|
data->unix_pass = (char*)password;
|
34
34
|
data->itoken = GSS_C_NO_BUFFER;
|
35
|
-
if (check_tokens(data) != 1)
|
36
|
-
|
35
|
+
if (check_tokens(data) != 1) {
|
36
|
+
free(data);
|
37
|
+
return Qfalse;
|
38
|
+
}
|
37
39
|
|
38
40
|
token = (unsigned char*)strdup(data->otoken.value);
|
39
41
|
token_base64 = base64_encode((const unsigned char*)data->otoken.value, data->otoken.length, &elen);
|
data/lib/netsoul/location.rb
CHANGED
data/lib/netsoul/message.rb
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'digest/md5'
|
3
|
+
require 'uri'
|
4
|
+
|
5
|
+
require_relative 'location'
|
6
|
+
|
1
7
|
module Netsoul
|
2
8
|
class Message
|
3
9
|
class << self
|
@@ -9,16 +15,13 @@ module Netsoul
|
|
9
15
|
end
|
10
16
|
|
11
17
|
def standard_auth(config)
|
12
|
-
login = config.login
|
13
18
|
client_ip = config.user_connection_info[:client_ip]
|
14
|
-
|
15
|
-
location = Message.escape(Location.get(client_ip) == 'ext'.freeze ? user_custom_location : Location.get(client_ip))
|
19
|
+
location = Message.escape(Location.get(client_ip) == 'ext'.freeze ? config.location : Location.get(client_ip))
|
16
20
|
client_name = Message.escape(config.client_name)
|
17
|
-
"ext_user_log #{login} #{_standard_auth_string(config)} #{client_name} #{location}"
|
21
|
+
"ext_user_log #{config.login} #{_standard_auth_string(config)} #{client_name} #{location}"
|
18
22
|
end
|
19
23
|
|
20
24
|
def _kerberos_get
|
21
|
-
require 'netsoul_kerberos'
|
22
25
|
@netsoul_kerberos ||= NetsoulKerberos.new
|
23
26
|
rescue LoadError => e
|
24
27
|
raise Netsoul::Error, "NetsoulKerberos library not found: #{e}.".freeze
|
@@ -32,6 +35,8 @@ module Netsoul
|
|
32
35
|
end
|
33
36
|
|
34
37
|
def kerberos_auth(config)
|
38
|
+
require 'netsoul_kerberos'
|
39
|
+
|
35
40
|
unless _kerberos_get.build_token(config.login, config.unix_password)
|
36
41
|
fail Netsoul::Error, 'Impossible to retrieve the kerberos token.'.freeze
|
37
42
|
end
|
@@ -39,7 +44,7 @@ module Netsoul
|
|
39
44
|
end
|
40
45
|
|
41
46
|
def auth_ag
|
42
|
-
'auth_ag ext_user none
|
47
|
+
'auth_ag ext_user none none'.freeze
|
43
48
|
end
|
44
49
|
|
45
50
|
def send_message(user, msg)
|
data/lib/netsoul/version.rb
CHANGED