winevt_c 0.7.0 → 0.7.1

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
  SHA256:
3
- metadata.gz: a1e26f9f7aef69fdf599f08c4c309fd1a60e00178d0a4db7a24b76cde7376254
4
- data.tar.gz: 20e705a60f389912acd1594eecd0ea1a79230de00e887b0033016ccf72d8383f
3
+ metadata.gz: 4aea52298871b70f5fa9f0c01227cd4afb79a188b75e4870a680ed435b7d19fe
4
+ data.tar.gz: 26ac8f251f2dd6cf077f7481066d1305e023986438a0fbd50fe9fec9dd97c266
5
5
  SHA512:
6
- metadata.gz: ec1d0dfbf4c1ec66619a709e012c76ab5487944f1c2970520b09ed46d9f3689d8ab5dcfc4499e34aeb2cde111f571e652cbf6bf337c20c5b7d5d836ef602d4ab
7
- data.tar.gz: '01842dfd20afb70a08a928baf7d38c1c3c3df79a7ffd9303275d25623520b1f3e81adfcfcd43a730e8e36cb6931933c48871bd72bb3a21b9bbc33bde91bda366'
6
+ metadata.gz: 6e6683d23e26dfa60e4a4e31bb03a434f2e01025c1072de8930d8ca98b7090dd4128711540c65ba35b5d53ca142251bc5eb3881ad1df1af3679c5d84faa2b1f7
7
+ data.tar.gz: b83a9f1f27428c75f9735297fa19abae507240956a587df4b38c9f0b983f4f1ed82dc4c30ccd64fe4cb12ad7b8ae7b6a70bb89c50bd3e280a568c9eda768d7a2
@@ -0,0 +1,13 @@
1
+ require 'winevt'
2
+
3
+ @channels = Winevt::EventLog::Channel.new
4
+ @channels.force_enumerate = false
5
+ result = []
6
+ @channels.each do |channel|
7
+ result << channel
8
+ end
9
+
10
+ puts "length of channels: #{result.length}"
11
+ result.each do |r|
12
+ puts r
13
+ end
@@ -47,6 +47,7 @@ VALUE rb_eWinevtQueryError;
47
47
  struct WinevtChannel
48
48
  {
49
49
  EVT_HANDLE channels;
50
+ BOOL force_enumerate;
50
51
  };
51
52
 
52
53
  struct WinevtBookmark
@@ -9,12 +9,16 @@
9
9
  * require 'winevt'
10
10
  * channels = []
11
11
  * @channel = Winevt::EventLog::Channel.new
12
+ * # If users want to retrive all channel name, it should be set as true.
13
+ * @channel.force_enumerate = false
12
14
  * @channel.each do |channel|
13
15
  * channels << channel
14
16
  * end
15
17
  * print channels
16
18
  */
17
19
 
20
+ DWORD is_subscribable_channel_p(EVT_HANDLE hChannel, BOOL force_enumerate);
21
+ DWORD check_subscribable_with_channel_config_type(int Id, PEVT_VARIANT pProperty, BOOL force_enumerate);
18
22
  static void channel_free(void* ptr);
19
23
 
20
24
  static const rb_data_type_t rb_winevt_channel_type = { "winevt/channel",
@@ -54,11 +58,121 @@ rb_winevt_channel_alloc(VALUE klass)
54
58
  *
55
59
  */
56
60
  static VALUE
57
- rb_winevt_channel_initialize(VALUE klass)
61
+ rb_winevt_channel_initialize(VALUE self)
58
62
  {
63
+ struct WinevtChannel* winevtChannel;
64
+
65
+ TypedData_Get_Struct(
66
+ self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
67
+
68
+ winevtChannel->force_enumerate = FALSE;
69
+
59
70
  return Qnil;
60
71
  }
61
72
 
73
+ /*
74
+ * This method specifies whether forcing to enumerate channel which
75
+ * type is Debug and Analytical or not.
76
+ *
77
+ * @param rb_force_enumerate_p [Boolean]
78
+ * @since 0.7.1
79
+ */
80
+ static VALUE
81
+ rb_winevt_channel_set_force_enumerate(VALUE self, VALUE rb_force_enumerate_p)
82
+ {
83
+ struct WinevtChannel* winevtChannel;
84
+
85
+ TypedData_Get_Struct(
86
+ self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
87
+
88
+ winevtChannel->force_enumerate = RTEST(rb_force_enumerate_p);
89
+
90
+ return Qnil;
91
+ }
92
+
93
+ /*
94
+ * This method returns whether forcing to enumerate channel which type
95
+ * is Debug and Analytical or not.
96
+ *
97
+ * @return [Boolean]
98
+ * @since 0.7.1
99
+ */
100
+ static VALUE
101
+ rb_winevt_channel_get_force_enumerate(VALUE self)
102
+ {
103
+ struct WinevtChannel* winevtChannel;
104
+
105
+ TypedData_Get_Struct(
106
+ self, struct WinevtChannel, &rb_winevt_channel_type, winevtChannel);
107
+
108
+ return winevtChannel->force_enumerate ? Qtrue : Qfalse;
109
+ }
110
+
111
+ DWORD is_subscribable_channel_p(EVT_HANDLE hChannel, BOOL force_enumerate)
112
+ {
113
+ PEVT_VARIANT pProperty = NULL;
114
+ PEVT_VARIANT pTemp = NULL;
115
+ DWORD dwBufferSize = 0;
116
+ DWORD dwBufferUsed = 0;
117
+ DWORD status = ERROR_SUCCESS;
118
+
119
+ for (int Id = 0; Id < EvtChannelConfigPropertyIdEND; Id++) {
120
+ if (!EvtGetChannelConfigProperty(hChannel, (EVT_CHANNEL_CONFIG_PROPERTY_ID)Id, 0, dwBufferSize, pProperty, &dwBufferUsed)) {
121
+ status = GetLastError();
122
+ if (ERROR_INSUFFICIENT_BUFFER == status) {
123
+ dwBufferSize = dwBufferUsed;
124
+ pTemp = (PEVT_VARIANT)realloc(pProperty, dwBufferSize);
125
+ if (pTemp) {
126
+ pProperty = pTemp;
127
+ pTemp = NULL;
128
+ EvtGetChannelConfigProperty(hChannel, (EVT_CHANNEL_CONFIG_PROPERTY_ID)Id, 0, dwBufferSize, pProperty, &dwBufferUsed);
129
+ } else {
130
+ free(pProperty);
131
+
132
+ status = ERROR_OUTOFMEMORY;
133
+ rb_raise(rb_eRuntimeError, "realloc failed with %ld\n", status);
134
+ }
135
+ }
136
+
137
+ if (ERROR_SUCCESS != (status = GetLastError())) {
138
+ free(pProperty);
139
+
140
+ rb_raise(rb_eRuntimeError, "EvtGetChannelConfigProperty failed with %ld\n", GetLastError());
141
+ }
142
+ }
143
+
144
+ status = check_subscribable_with_channel_config_type(Id, pProperty, force_enumerate);
145
+ if (status != ERROR_SUCCESS)
146
+ break;
147
+ }
148
+
149
+ free(pProperty);
150
+
151
+ return status;
152
+ }
153
+
154
+ #define EVENT_DEBUG_TYPE 2
155
+ #define EVENT_ANALYTICAL_TYPE 3
156
+
157
+ DWORD check_subscribable_with_channel_config_type(int Id, PEVT_VARIANT pProperty, BOOL force_enumerate)
158
+ {
159
+ DWORD status = ERROR_SUCCESS;
160
+ switch(Id) {
161
+ case EvtChannelConfigType:
162
+ if (!force_enumerate &&
163
+ (pProperty->UInt32Val == EVENT_DEBUG_TYPE ||
164
+ pProperty->UInt32Val == EVENT_ANALYTICAL_TYPE)) {
165
+ return ERROR_INVALID_DATA;
166
+ }
167
+ break;
168
+ }
169
+
170
+ return status;
171
+ }
172
+
173
+ #undef EVENT_DEBUG_TYPE
174
+ #undef EVENT_ANALYTICAL_TYPE
175
+
62
176
  /*
63
177
  * Enumerate Windows EventLog channels
64
178
  *
@@ -69,6 +183,7 @@ static VALUE
69
183
  rb_winevt_channel_each(VALUE self)
70
184
  {
71
185
  EVT_HANDLE hChannels;
186
+ EVT_HANDLE hChannelConfig = NULL;
72
187
  struct WinevtChannel* winevtChannel;
73
188
  char errBuf[256];
74
189
  LPWSTR buffer = NULL;
@@ -124,6 +239,23 @@ rb_winevt_channel_each(VALUE self)
124
239
  rb_raise(rb_eRuntimeError, errBuf);
125
240
  }
126
241
  }
242
+ hChannelConfig = EvtOpenChannelConfig(NULL, buffer, 0);
243
+ if (NULL == hChannelConfig) {
244
+ _snprintf_s(errBuf,
245
+ _countof(errBuf),
246
+ _TRUNCATE,
247
+ "EvtOpenChannelConfig failed with %lu.\n",
248
+ GetLastError());
249
+ free(buffer);
250
+ buffer = NULL;
251
+ bufferSize = 0;
252
+
253
+ rb_raise(rb_eRuntimeError, errBuf);
254
+ }
255
+
256
+ status = is_subscribable_channel_p(hChannelConfig, winevtChannel->force_enumerate);
257
+ if (status != ERROR_SUCCESS)
258
+ continue;
127
259
 
128
260
  utf8str = wstr_to_rb_str(CP_UTF8, buffer, -1);
129
261
 
@@ -151,4 +283,6 @@ Init_winevt_channel(VALUE rb_cEventLog)
151
283
  rb_define_alloc_func(rb_cChannel, rb_winevt_channel_alloc);
152
284
  rb_define_method(rb_cChannel, "initialize", rb_winevt_channel_initialize, 0);
153
285
  rb_define_method(rb_cChannel, "each", rb_winevt_channel_each, 0);
286
+ rb_define_method(rb_cChannel, "force_enumerate", rb_winevt_channel_get_force_enumerate, 0);
287
+ rb_define_method(rb_cChannel, "force_enumerate=", rb_winevt_channel_set_force_enumerate, 1);
154
288
  }
@@ -1,3 +1,3 @@
1
1
  module Winevt
2
- VERSION = "0.7.0"
2
+ VERSION = "0.7.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: winevt_c
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hiroshi Hatake
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-02-14 00:00:00.000000000 Z
11
+ date: 2020-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -119,6 +119,7 @@ files:
119
119
  - bin/console
120
120
  - bin/setup
121
121
  - example/bookmark.rb
122
+ - example/enumerate_channels.rb
122
123
  - example/eventlog.rb
123
124
  - example/rate_limit.rb
124
125
  - example/tailing.rb