netsoul 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7e2e58b89442fb6a9040b0d79d6bf4ca618d0131
4
- data.tar.gz: 6d058ba823d2d325eda211680f7e5afe685dccce
3
+ metadata.gz: 7c87d6edb74b1dd1b82b6617944658c472f8ceff
4
+ data.tar.gz: 705d281ad0c3174ad5aadbfc9dbaa367e14dae8e
5
5
  SHA512:
6
- metadata.gz: 9389e6a25f64b6003432a3112199ac8db11efd95b1a601eb32f7e72f4127aa66bf1ce494e033e03b3a36db5fd880964a30ceaf6caafee21684ee9d3748cdba93
7
- data.tar.gz: 2d2a97bdc444a1d6adfb58b74b61a9c1c64bf8c9dc287bc0e0a447ac833ea70be2bfd432ec66ebcdbef57f39fdb3ac5a8085fd297096c3216791be693c381f2d
6
+ metadata.gz: 2facc495620c54c44ef89d081ce5a2e3794f39937ff96887af617a330907a42144ffb90d4f5a2c8b731332e9679bdba4c44e516bc9cdbe88f1b5037b7738b1c3
7
+ data.tar.gz: 3537edb9e19b2dd4048d9c744f7dd7728d8bf8bee601d514352c8124e7c80ec1c8401859cfa40c57b685509981dbf99f04ff2c726301420d189a4e0e46e15d71
data/.rubocop.yml CHANGED
@@ -21,4 +21,4 @@ Style/Documentation:
21
21
 
22
22
  AllCops:
23
23
  Excludes:
24
- - 'bin/**'
24
+ - 'bin/**/*'
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Netsoul-Ruby [![Gem Version](https://badge.fury.io/rb/netsoul-ruby.svg)](http://badge.fury.io/rb/netsoul-ruby) [![Build Status](https://travis-ci.org/fenicks/netsoul-ruby.svg?branch=master)](https://travis-ci.org/fenicks/netsoul-ruby) [![Coverage Status](https://coveralls.io/repos/fenicks/netsoul-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/fenicks/netsoul-ruby?branch=master)
1
+ # Netsoul-Ruby [![Gem Version](https://badge.fury.io/rb/netsoul.svg)](http://badge.fury.io/rb/netsoul) [![Build Status](https://travis-ci.org/fenicks/netsoul-ruby.svg?branch=master)](https://travis-ci.org/fenicks/netsoul-ruby) [![Coverage Status](https://coveralls.io/repos/fenicks/netsoul-ruby/badge.svg?branch=master&service=github)](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
- ```ruby
29
- # Gemfile
26
+ #### Gemfile
27
+
30
28
  gem 'netsoul', '~> 0.1'
31
- ```
32
29
 
33
- ```ruby
34
- # project.rb
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 'base64'
7
- require 'digest/md5'
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
- # if __FILE__ == $PROGRAM_NAME
86
- $stderr.sync = true
87
- require 'optparse'
88
- require 'yaml'
89
-
90
- options = {}
91
- OptionParser.new do |opts|
92
- opts.banner = 'Usage: netsoul-ruby [options]'.freeze
93
- opts.separator "\nNetsoul-Ruby options:".freeze
94
- opts.on('-c'.freeze, '--config FILE'.freeze, 'Configuration file in YAML'.freeze) do |file|
95
- options[:config] = file
96
- unless File.file?(options[:config])
97
- puts '[ERROR] Configuration is not a valid file'
98
- exit
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
- end.parse!
101
+ options[:user_opts] = YAML.load_file(options[:config])
102
+ end
107
103
 
108
- unless options.include?(:config)
109
- puts '[ERROR] Configuration file is not provided'
104
+ opts.on('-h', '--help', 'Display this screen') do
105
+ puts opts
110
106
  exit
111
107
  end
108
+ end.parse!
112
109
 
113
- c = Netsoul::Client.new options[:user_opts]
114
- c.connect
115
- if c.started
116
- loop do
117
- res = c.sock_get
118
- c.sock_send res if res.to_s.match(/^ping.*/)
119
- sleep 1
120
- end
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
- # end
123
+ end
@@ -17,22 +17,22 @@
17
17
 
18
18
  void display_status(k_data_t *data)
19
19
  {
20
- OM_uint32 minor, status;
21
- gss_buffer_desc msg;
20
+ OM_uint32 minor, status;
21
+ gss_buffer_desc msg;
22
22
 
23
- gss_display_status(&minor, data->min, GSS_C_GSS_CODE, GSS_C_NO_OID, &status, &msg);
24
- if (msg.value) puts(msg.value);
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( k_data_t *data,
28
- krb5_context context,
29
- krb5_principal principal,
30
- krb5_ccache ccache)
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 ret;
33
- krb5_get_init_creds_opt opt;
34
- krb5_creds cred;
35
- // char * password = NULL;
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 ret;
65
- krb5_context context;
66
- krb5_ccache ccache;
67
- krb5_principal 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
- OM_uint32 min;
88
- OM_uint32 maj;
89
- gss_buffer_desc buf;
87
+ OM_uint32 min;
88
+ OM_uint32 maj;
89
+ gss_buffer_desc buf;
90
90
 
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);
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
- if (maj != GSS_S_COMPLETE)
96
- display_status(data);
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
- 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);
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 * base64_encode(const unsigned char *src, size_t len, size_t *out_len)
165
+ unsigned char* base64_encode(const unsigned char *src, size_t len, size_t *out_len)
166
166
  {
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;
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* login;
25
- char* unix_pass;
26
- OM_uint32 min;
27
- OM_uint32 maj;
28
- gss_name_t gss_name;
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( k_data_t *data,
39
- krb5_context context,
40
- krb5_principal principal,
41
- krb5_ccache ccache);
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", 1, 1);
18
- rb_define_attr(cNetsoulKerberos, "password", 1, 1);
19
- rb_define_attr(cNetsoulKerberos, "token", 1, 0);
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 *data;
27
- unsigned char *token_base64;
28
- unsigned char *token;
29
- size_t elen;
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
- return Qfalse;
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);
@@ -3,11 +3,7 @@ module Netsoul
3
3
  class << self
4
4
  def get(ip)
5
5
  locations.each do |key, val|
6
- res = ip.match(/^#{val}/)
7
- if res
8
- res = "#{key}"
9
- return res
10
- end
6
+ return "#{key}".freeze if ip.match(/^#{val}/)
11
7
  end
12
8
  'ext'.freeze
13
9
  end
@@ -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
- user_custom_location = config.location
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 -'.freeze
47
+ 'auth_ag ext_user none none'.freeze
43
48
  end
44
49
 
45
50
  def send_message(user, msg)
@@ -1,3 +1,3 @@
1
1
  module Netsoul
2
- VERSION = '0.3.0'.freeze
2
+ VERSION = '0.4.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: netsoul
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christian Kakesa