postfix_status_line 0.2.4 → 0.2.5
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/.travis.yml +8 -0
- data/README.md +6 -0
- data/ext/digest_sha.h +40 -0
- data/ext/postfix_status_line_core.c +53 -45
- data/ext/postfix_status_line_core.h +3 -0
- data/lib/postfix_status_line/version.rb +1 -1
- data/lib/postfix_status_line.rb +4 -1
- data/test.txt +0 -0
- metadata +18 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 16f4978cc397f853ac95847d796142dc55e7e37f
|
4
|
+
data.tar.gz: 8e1134c395cb76a686a1cd759f6f3f4263428337
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 93bfa44661495628f3a7b9b89180fe2b40a4feedaac6e3e46a647ea2f80fcf528a005f51c4c999f37115f99dd82b3142e5a3bf2f9e691f0f60525b9943550464
|
7
|
+
data.tar.gz: d3b1fcfa308b897c340fdfd091d1805458b4d7bf793ccd13699fb25a253e08e30b631621c17831e94d9b81dda21bc3504bd7e3513a0608d77db67f79b40a1edc
|
data/.travis.yml
CHANGED
@@ -3,6 +3,14 @@ rvm:
|
|
3
3
|
- 2.0.0
|
4
4
|
- 2.1
|
5
5
|
- 2.2
|
6
|
+
- 2.3.0
|
7
|
+
before_install:
|
8
|
+
- gem update bundler
|
9
|
+
before_script:
|
10
|
+
- '[ "$DISABLE_OPENSSL" = "1" ] && sudo apt-get remove -y libssl-dev || true'
|
6
11
|
script:
|
7
12
|
- bundle install
|
8
13
|
- bundle exec rake
|
14
|
+
env:
|
15
|
+
- DISABLE_OPENSSL=0
|
16
|
+
- DISABLE_OPENSSL=1
|
data/README.md
CHANGED
@@ -51,6 +51,12 @@ PostfixStatusLine.parse(status_line)
|
|
51
51
|
PostfixStatusLine.parse(status_line, hash: true)
|
52
52
|
```
|
53
53
|
|
54
|
+
### Specify SHA algorithm
|
55
|
+
|
56
|
+
```ruby
|
57
|
+
PostfixStatusLine.parse(status_line, hash: true, sha_algorithm: 256)
|
58
|
+
```
|
59
|
+
|
54
60
|
### Parse time
|
55
61
|
|
56
62
|
```ruby
|
data/ext/digest_sha.h
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#ifndef __DIGEST_SHA_H__
|
2
|
+
#define __DIGEST_SHA_H__
|
3
|
+
|
4
|
+
#ifndef SHA224_CTX
|
5
|
+
#define SHA224_CTX SHA256_CTX
|
6
|
+
#endif
|
7
|
+
|
8
|
+
#ifndef SHA384_CTX
|
9
|
+
#define SHA384_CTX SHA512_CTX
|
10
|
+
#endif
|
11
|
+
|
12
|
+
#define DEFINE_SHA_FUNCTIONS(SHA_ALGO) \
|
13
|
+
static void sha##SHA_ALGO##_to_str(unsigned char *hash, char buf[]) { \
|
14
|
+
int i; \
|
15
|
+
for (i = 0; i < SHA##SHA_ALGO##_DIGEST_LENGTH; i++) { \
|
16
|
+
snprintf(buf + (i * 2), 3, "%02x", hash[i]); \
|
17
|
+
} \
|
18
|
+
} \
|
19
|
+
static bool digest_sha##SHA_ALGO(char *str, char *salt, size_t salt_len, char buf[]) { \
|
20
|
+
SHA##SHA_ALGO##_CTX ctx; \
|
21
|
+
unsigned char hash[SHA##SHA_ALGO##_DIGEST_LENGTH]; \
|
22
|
+
if (SHA##SHA_ALGO##_Init(&ctx) != 1) { \
|
23
|
+
return false; \
|
24
|
+
} \
|
25
|
+
if (SHA##SHA_ALGO##_Update(&ctx, str, strlen(str)) != 1) { \
|
26
|
+
return false; \
|
27
|
+
} \
|
28
|
+
if (salt != NULL) { \
|
29
|
+
if (SHA##SHA_ALGO##_Update(&ctx, salt, salt_len) != 1) { \
|
30
|
+
return false; \
|
31
|
+
} \
|
32
|
+
} \
|
33
|
+
if (SHA##SHA_ALGO##_Final(hash, &ctx) != 1) { \
|
34
|
+
return false; \
|
35
|
+
} \
|
36
|
+
sha##SHA_ALGO##_to_str(hash, buf); \
|
37
|
+
return true; \
|
38
|
+
}
|
39
|
+
|
40
|
+
#endif // __DIGEST_SHA_H__
|
@@ -1,40 +1,13 @@
|
|
1
1
|
#include "postfix_status_line_core.h"
|
2
2
|
|
3
3
|
#ifdef HAVE_OPENSSL_SHA_H
|
4
|
-
static void sha512_to_str(unsigned char *hash, char buf[]) {
|
5
|
-
int i;
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
static bool digest_sha512(char *str, char *salt, size_t salt_len, char buf[]) {
|
13
|
-
SHA512_CTX ctx;
|
14
|
-
unsigned char hash[SHA512_DIGEST_LENGTH];
|
15
|
-
|
16
|
-
if (SHA512_Init(&ctx) != 1) {
|
17
|
-
return false;
|
18
|
-
}
|
19
|
-
|
20
|
-
if (SHA512_Update(&ctx, str, strlen(str)) != 1) {
|
21
|
-
return false;
|
22
|
-
}
|
5
|
+
DEFINE_SHA_FUNCTIONS(); // SHA1
|
6
|
+
DEFINE_SHA_FUNCTIONS(224);
|
7
|
+
DEFINE_SHA_FUNCTIONS(256);
|
8
|
+
DEFINE_SHA_FUNCTIONS(384);
|
9
|
+
DEFINE_SHA_FUNCTIONS(512);
|
23
10
|
|
24
|
-
if (salt != NULL) {
|
25
|
-
if (SHA512_Update(&ctx, salt, salt_len) != 1) {
|
26
|
-
return false;
|
27
|
-
}
|
28
|
-
}
|
29
|
-
|
30
|
-
if (SHA512_Final(hash, &ctx) != 1) {
|
31
|
-
return false;
|
32
|
-
}
|
33
|
-
|
34
|
-
sha512_to_str(hash, buf);
|
35
|
-
|
36
|
-
return true;
|
37
|
-
}
|
38
11
|
#endif // HAVE_OPENSSL_SHA_H
|
39
12
|
|
40
13
|
static bool rb_value_to_bool(VALUE v_value) {
|
@@ -208,10 +181,11 @@ static void put_status(char *value, VALUE hash, bool mask) {
|
|
208
181
|
}
|
209
182
|
|
210
183
|
#ifdef HAVE_OPENSSL_SHA_H
|
211
|
-
static void put_hash(char *email, VALUE hash_obj, char *salt, size_t salt_len) {
|
184
|
+
static void put_hash(char *email, VALUE hash_obj, char *salt, size_t salt_len, DIGEST_SHA digest_sha_func) {
|
185
|
+
// XXX: allocate a buffer of sufficient size
|
212
186
|
char buf[SHA512_DIGEST_LENGTH * 2 + 1];
|
213
187
|
|
214
|
-
if (!
|
188
|
+
if (!digest_sha_func(email, salt, salt_len, buf)) {
|
215
189
|
return;
|
216
190
|
}
|
217
191
|
|
@@ -219,12 +193,12 @@ static void put_hash(char *email, VALUE hash_obj, char *salt, size_t salt_len) {
|
|
219
193
|
}
|
220
194
|
#endif // HAVE_OPENSSL_SHA_H
|
221
195
|
|
222
|
-
static void put_to(char *value, VALUE hash, bool mask, bool include_hash, char *salt, size_t salt_len) {
|
196
|
+
static void put_to(char *value, VALUE hash, bool mask, bool include_hash, char *salt, size_t salt_len, DIGEST_SHA digest_sha_func) {
|
223
197
|
char *email = remove_bracket(value);
|
224
198
|
|
225
199
|
#ifdef HAVE_OPENSSL_SHA_H
|
226
200
|
if (include_hash) {
|
227
|
-
put_hash(email, hash, salt, salt_len);
|
201
|
+
put_hash(email, hash, salt, salt_len, digest_sha_func);
|
228
202
|
}
|
229
203
|
#endif
|
230
204
|
|
@@ -246,7 +220,7 @@ static void put_from(char *value, VALUE hash, bool mask) {
|
|
246
220
|
rb_hash_aset(hash, rb_str_new2("from"), rb_str_new2(email));
|
247
221
|
}
|
248
222
|
|
249
|
-
static void put_attr(char *str, VALUE hash, bool mask, bool include_hash, char *salt, size_t salt_len) {
|
223
|
+
static void put_attr(char *str, VALUE hash, bool mask, bool include_hash, char *salt, size_t salt_len, DIGEST_SHA digest_sha_func) {
|
250
224
|
char *value = strchr(str, '=');
|
251
225
|
|
252
226
|
if (value == NULL) {
|
@@ -263,7 +237,7 @@ static void put_attr(char *str, VALUE hash, bool mask, bool include_hash, char *
|
|
263
237
|
} else if (strcmp(str, "conn_use") == 0) {
|
264
238
|
rb_hash_aset(hash, v_key, INT2NUM(atoi(value)));
|
265
239
|
} else if (strcmp(str, "to") == 0) {
|
266
|
-
put_to(value, hash, mask, include_hash, salt, salt_len);
|
240
|
+
put_to(value, hash, mask, include_hash, salt, salt_len, digest_sha_func);
|
267
241
|
} else if (strcmp(str, "from") == 0) {
|
268
242
|
put_from(value, hash, mask);
|
269
243
|
} else if (strcmp(str, "status") == 0) {
|
@@ -277,7 +251,7 @@ static void put_attr(char *str, VALUE hash, bool mask, bool include_hash, char *
|
|
277
251
|
}
|
278
252
|
}
|
279
253
|
|
280
|
-
static void split_line2(char *str, bool mask, VALUE hash, bool include_hash, char *salt, size_t salt_len) {
|
254
|
+
static void split_line2(char *str, bool mask, VALUE hash, bool include_hash, char *salt, size_t salt_len, DIGEST_SHA digest_sha_func) {
|
281
255
|
char *ptr;
|
282
256
|
|
283
257
|
for (;;) {
|
@@ -287,7 +261,7 @@ static void split_line2(char *str, bool mask, VALUE hash, bool include_hash, cha
|
|
287
261
|
break;
|
288
262
|
}
|
289
263
|
|
290
|
-
put_attr(ptr, hash, mask, include_hash, salt, salt_len);
|
264
|
+
put_attr(ptr, hash, mask, include_hash, salt, salt_len, digest_sha_func);
|
291
265
|
|
292
266
|
if (strncmp(str, "status=", 7) == 0) {
|
293
267
|
break;
|
@@ -295,7 +269,7 @@ static void split_line2(char *str, bool mask, VALUE hash, bool include_hash, cha
|
|
295
269
|
}
|
296
270
|
|
297
271
|
if (str) {
|
298
|
-
put_attr(str, hash, mask, include_hash, salt, salt_len);
|
272
|
+
put_attr(str, hash, mask, include_hash, salt, salt_len, digest_sha_func);
|
299
273
|
}
|
300
274
|
}
|
301
275
|
|
@@ -341,7 +315,7 @@ static void put_epoch(char *time_str, VALUE hash) {
|
|
341
315
|
rb_hash_aset(hash, rb_str_new2("epoch"), LONG2NUM(ts));
|
342
316
|
}
|
343
317
|
|
344
|
-
static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time) {
|
318
|
+
static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask, VALUE v_hash, VALUE v_salt, VALUE v_parse_time, VALUE v_sha_algo) {
|
345
319
|
Check_Type(v_str, T_STRING);
|
346
320
|
|
347
321
|
char *str = RSTRING_PTR(v_str);
|
@@ -358,7 +332,7 @@ static VALUE rb_postfix_status_line_parse(VALUE self, VALUE v_str, VALUE v_mask,
|
|
358
332
|
char *salt = NULL;
|
359
333
|
size_t salt_len = -1;
|
360
334
|
|
361
|
-
if (rb_value_to_bool(v_hash)) {
|
335
|
+
if (rb_value_to_bool(v_hash)) {
|
362
336
|
#ifdef HAVE_OPENSSL_SHA_H
|
363
337
|
include_hash = true;
|
364
338
|
|
@@ -372,6 +346,40 @@ if (rb_value_to_bool(v_hash)) {
|
|
372
346
|
#endif // HAVE_OPENSSL_SHA_H
|
373
347
|
}
|
374
348
|
|
349
|
+
int sha_algo = 512;
|
350
|
+
|
351
|
+
if (!NIL_P(v_sha_algo)) {
|
352
|
+
#ifdef HAVE_OPENSSL_SHA_H
|
353
|
+
sha_algo = NUM2INT(v_sha_algo);
|
354
|
+
#else
|
355
|
+
rb_raise(rb_eArgError, "OpenSSL is not linked");
|
356
|
+
#endif // HAVE_OPENSSL_SHA_H
|
357
|
+
}
|
358
|
+
|
359
|
+
DIGEST_SHA digest_sha_func = NULL;
|
360
|
+
|
361
|
+
#ifdef HAVE_OPENSSL_SHA_H
|
362
|
+
switch (sha_algo) {
|
363
|
+
case 1:
|
364
|
+
digest_sha_func = digest_sha;
|
365
|
+
break;
|
366
|
+
case 224:
|
367
|
+
digest_sha_func = digest_sha224;
|
368
|
+
break;
|
369
|
+
case 256:
|
370
|
+
digest_sha_func = digest_sha256;
|
371
|
+
break;
|
372
|
+
case 384:
|
373
|
+
digest_sha_func = digest_sha384;
|
374
|
+
break;
|
375
|
+
case 512:
|
376
|
+
digest_sha_func = digest_sha512;
|
377
|
+
break;
|
378
|
+
default:
|
379
|
+
rb_raise(rb_eArgError, "Invalid SHA algorithm");
|
380
|
+
}
|
381
|
+
#endif // HAVE_OPENSSL_SHA_H
|
382
|
+
|
375
383
|
char buf[len + 1];
|
376
384
|
strncpy(buf, str, len);
|
377
385
|
buf[len] = '\0';
|
@@ -392,7 +400,7 @@ if (rb_value_to_bool(v_hash)) {
|
|
392
400
|
put_epoch(tm, hash);
|
393
401
|
}
|
394
402
|
|
395
|
-
split_line2(attrs, mask, hash, include_hash, salt, salt_len);
|
403
|
+
split_line2(attrs, mask, hash, include_hash, salt, salt_len, digest_sha_func);
|
396
404
|
|
397
405
|
return hash;
|
398
406
|
}
|
@@ -400,5 +408,5 @@ if (rb_value_to_bool(v_hash)) {
|
|
400
408
|
void Init_postfix_status_line_core() {
|
401
409
|
VALUE rb_mPostfixStatusLine = rb_define_module("PostfixStatusLine");
|
402
410
|
VALUE rb_mPostfixStatusLineCore = rb_define_module_under(rb_mPostfixStatusLine, "Core");
|
403
|
-
rb_define_module_function(rb_mPostfixStatusLineCore, "parse", rb_postfix_status_line_parse,
|
411
|
+
rb_define_module_function(rb_mPostfixStatusLineCore, "parse", rb_postfix_status_line_parse, 6);
|
404
412
|
}
|
data/lib/postfix_status_line.rb
CHANGED
@@ -2,12 +2,15 @@ require 'postfix_status_line/version'
|
|
2
2
|
require 'postfix_status_line_core'
|
3
3
|
|
4
4
|
module PostfixStatusLine
|
5
|
+
SHA_ALGORITHM = %w(1 224 256 384 512)
|
6
|
+
|
5
7
|
def parse(str, options = {})
|
6
8
|
mask = options.has_key?(:mask) ? options[:mask] : true
|
7
9
|
hash = options[:hash]
|
8
10
|
salt = options[:salt]
|
9
11
|
parse_time = options[:parse_time]
|
10
|
-
|
12
|
+
sha_algo = options[:sha_algorithm]
|
13
|
+
PostfixStatusLine::Core.parse(str, mask, hash, salt, parse_time, sha_algo)
|
11
14
|
end
|
12
15
|
module_function :parse
|
13
16
|
end
|
data/test.txt
ADDED
File without changes
|
metadata
CHANGED
@@ -1,69 +1,69 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: postfix_status_line
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake-compiler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
description: Postfix Status Line Log Parser implemented by C.
|
@@ -74,21 +74,23 @@ extensions:
|
|
74
74
|
- ext/extconf.rb
|
75
75
|
extra_rdoc_files: []
|
76
76
|
files:
|
77
|
-
- .gitignore
|
78
|
-
- .rspec
|
79
|
-
- .travis.yml
|
77
|
+
- ".gitignore"
|
78
|
+
- ".rspec"
|
79
|
+
- ".travis.yml"
|
80
80
|
- Gemfile
|
81
81
|
- LICENSE.txt
|
82
82
|
- README.md
|
83
83
|
- Rakefile
|
84
84
|
- bin/console
|
85
85
|
- bin/setup
|
86
|
+
- ext/digest_sha.h
|
86
87
|
- ext/extconf.rb
|
87
88
|
- ext/postfix_status_line_core.c
|
88
89
|
- ext/postfix_status_line_core.h
|
89
90
|
- lib/postfix_status_line.rb
|
90
91
|
- lib/postfix_status_line/version.rb
|
91
92
|
- postfix_status_line.gemspec
|
93
|
+
- test.txt
|
92
94
|
homepage: https://github.com/winebarrel/postfix_status_line
|
93
95
|
licenses:
|
94
96
|
- MIT
|
@@ -100,17 +102,17 @@ require_paths:
|
|
100
102
|
- ext
|
101
103
|
required_ruby_version: !ruby/object:Gem::Requirement
|
102
104
|
requirements:
|
103
|
-
- -
|
105
|
+
- - ">="
|
104
106
|
- !ruby/object:Gem::Version
|
105
107
|
version: '0'
|
106
108
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
109
|
requirements:
|
108
|
-
- -
|
110
|
+
- - ">="
|
109
111
|
- !ruby/object:Gem::Version
|
110
112
|
version: '0'
|
111
113
|
requirements: []
|
112
114
|
rubyforge_project:
|
113
|
-
rubygems_version: 2.
|
115
|
+
rubygems_version: 2.5.2
|
114
116
|
signing_key:
|
115
117
|
specification_version: 4
|
116
118
|
summary: Postfix Status Line Log Parser implemented by C.
|