Class: Winevt::EventLog::Session

Inherits:
Object
  • Object
show all
Defined in:
ext/winevt/winevt_session.c,
lib/winevt/session.rb,
ext/winevt/winevt_session.c

Overview

Manage Session information for Windows EventLog.

Examples:

require 'winevt'

@session = Winevt::EventLog::Session.new("127.0.0.1")

@session.domain = "<EXAMPLEGROUP>"
@session.username = "<username>"
@session.password = "<password>"
# Then pass @session variable into Winevt::EventLog::Query or
# Winevt::EventLog::Subscribe#subscribe
@query = Winevt::EventLog::Query.new(
  "Application",
  "*[System[(Level <= 3) and TimeCreated[timediff(@SystemTime) <= 86400000]]]",
  @session
)
# some stuff.

@subscribe = Winevt::EventLog::Subscribe.new
@subscribe.subscribe(
  "Application",
  "*[System[(Level <= 4) and TimeCreated[timediff(@SystemTime) <= 86400000]]]",
  @session
)
# And some stuff.

Since:

  • v0.9.0

Defined Under Namespace

Modules: RpcLoginFlag

Instance Method Summary collapse

Constructor Details

#initializeSession

Returns a new instance of Session.



95
96
97
98
99
100
101
# File 'ext/winevt/winevt_session.c', line 95

def initialize(server, domain = nil, username = nil, password = nil)
  initialize_raw
  self.server = server
  self.domain = domain if domain.is_a?(String)
  self.username = username if username.is_a?(String)
  self.password = password if password.is_a?(String)
end

Instance Method Details

#domainObject



171
172
173
174
175
176
177
178
179
180
181
182
183
# File 'ext/winevt/winevt_session.c', line 171

static VALUE
rb_winevt_session_get_domain(VALUE self)
{
  struct WinevtSession* winevtSession;

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  if (winevtSession->domain) {
    return wstr_to_rb_str(CP_UTF8, winevtSession->domain, -1);
  } else {
    return rb_str_new2("(NULL)");
  }
}

#domain=(rb_domain) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'ext/winevt/winevt_session.c', line 190

static VALUE
rb_winevt_session_set_domain(VALUE self, VALUE rb_domain)
{
  struct WinevtSession* winevtSession;
  DWORD len;
  VALUE vdomainBuf;
  PWSTR wDomain;

  Check_Type(rb_domain, T_STRING);

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  len =
    MultiByteToWideChar(CP_UTF8, 0,
                        RSTRING_PTR(rb_domain), RSTRING_LEN(rb_domain),
                        NULL, 0);
  wDomain = ALLOCV_N(WCHAR, vdomainBuf, len + 1);
  MultiByteToWideChar(CP_UTF8, 0,
                      RSTRING_PTR(rb_domain), RSTRING_LEN(rb_domain),
                      wDomain, len);
  wDomain[len] = L'\0';

  if (winevtSession->domain)
    free(winevtSession->domain);
  winevtSession->domain = _wcsdup(wDomain);

  ALLOCV_END(vdomainBuf);

  return Qnil;
}

#flagsObject



339
340
341
342
343
344
345
346
347
# File 'ext/winevt/winevt_session.c', line 339

static VALUE
rb_winevt_session_get_flags(VALUE self)
{
  struct WinevtSession* winevtSession;

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  return LONG2NUM(winevtSession->flags);
}

#flags=(rb_flags) ⇒ Object



372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
# File 'ext/winevt/winevt_session.c', line 372

static VALUE
rb_winevt_session_set_flags(VALUE self, VALUE rb_flags)
{
  struct WinevtSession* winevtSession;
  EVT_RPC_LOGIN_FLAGS flags = EvtRpcLoginAuthDefault;

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  switch(TYPE(rb_flags)) {
    case T_SYMBOL:
      flags = get_session_rpc_login_flag_from_cstr(RSTRING_PTR(rb_sym2str(rb_flags)));
      break;
    case T_STRING:
      flags = get_session_rpc_login_flag_from_cstr(StringValuePtr(rb_flags));
      break;
    case T_FIXNUM:
      flags = NUM2LONG(rb_flags);
      break;
    default:
      rb_raise(rb_eArgError, "Expected Symbol, String or Fixnum in flags");
  }
  winevtSession->flags = flags;

  return Qnil;
}

#initialize_rawObject



4
# File 'lib/winevt/session.rb', line 4

alias_method :initialize_raw, :initialize

#passwordObject



281
282
283
284
285
286
287
288
289
290
291
292
293
# File 'ext/winevt/winevt_session.c', line 281

static VALUE
rb_winevt_session_get_password(VALUE self)
{
  struct WinevtSession* winevtSession;

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  if (winevtSession->password) {
    return wstr_to_rb_str(CP_UTF8, winevtSession->password, -1);
  } else {
    return rb_str_new2("(NULL)");
  }
}

#password=(rb_password) ⇒ Object



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'ext/winevt/winevt_session.c', line 300

static VALUE
rb_winevt_session_set_password(VALUE self, VALUE rb_password)
{
  struct WinevtSession* winevtSession;
  DWORD len;
  VALUE vpasswordBuf;
  PWSTR wPassword;

  Check_Type(rb_password, T_STRING);

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  len =
    MultiByteToWideChar(CP_UTF8, 0,
                        RSTRING_PTR(rb_password), RSTRING_LEN(rb_password),
                        NULL, 0);
  wPassword = ALLOCV_N(WCHAR, vpasswordBuf, len + 1);
  MultiByteToWideChar(CP_UTF8, 0,
                      RSTRING_PTR(rb_password), RSTRING_LEN(rb_password),
                      wPassword, len);
  wPassword[len] = L'\0';

  if (winevtSession->password) {
    SecureZeroMemory(winevtSession->password,
                     (wcslen(winevtSession->password) + 1) * sizeof(WCHAR));
    free(winevtSession->password);
  }
  winevtSession->password = _wcsdup(wPassword);

  ALLOCV_END(vpasswordBuf);

  return Qnil;
}

#serverObject



117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'ext/winevt/winevt_session.c', line 117

static VALUE
rb_winevt_session_get_server(VALUE self)
{
  struct WinevtSession* winevtSession;

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  if (winevtSession->server) {
    return wstr_to_rb_str(CP_UTF8, winevtSession->server, -1);
  } else {
    return rb_str_new2("(NULL)");
  }
}

#server=(rb_server) ⇒ Object



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'ext/winevt/winevt_session.c', line 136

static VALUE
rb_winevt_session_set_server(VALUE self, VALUE rb_server)
{
  struct WinevtSession* winevtSession;
  DWORD len;
  VALUE vserverBuf;
  PWSTR wServer;

  Check_Type(rb_server, T_STRING);

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  len =
    MultiByteToWideChar(CP_UTF8, 0,
                        RSTRING_PTR(rb_server), RSTRING_LEN(rb_server),
                        NULL, 0);
  wServer = ALLOCV_N(WCHAR, vserverBuf, len + 1);
  MultiByteToWideChar(CP_UTF8, 0,
                      RSTRING_PTR(rb_server), RSTRING_LEN(rb_server),
                      wServer, len);
  wServer[len] = L'\0';
  if (winevtSession->server)
    free(winevtSession->server);
  winevtSession->server = _wcsdup(wServer);

  ALLOCV_END(vserverBuf);

  return Qnil;
}

#usernameObject



226
227
228
229
230
231
232
233
234
235
236
237
238
# File 'ext/winevt/winevt_session.c', line 226

static VALUE
rb_winevt_session_get_username(VALUE self)
{
  struct WinevtSession* winevtSession;

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  if (winevtSession->username) {
    return wstr_to_rb_str(CP_UTF8, winevtSession->username, -1);
  } else {
    return rb_str_new2("(NULL)");
  }
}

#username=(rb_username) ⇒ Object



245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
# File 'ext/winevt/winevt_session.c', line 245

static VALUE
rb_winevt_session_set_username(VALUE self, VALUE rb_username)
{
  struct WinevtSession* winevtSession;
  DWORD len;
  VALUE vusernameBuf;
  PWSTR wUsername;

  Check_Type(rb_username, T_STRING);

  TypedData_Get_Struct(self, struct WinevtSession, &rb_winevt_session_type, winevtSession);

  len =
    MultiByteToWideChar(CP_UTF8, 0,
                        RSTRING_PTR(rb_username), RSTRING_LEN(rb_username),
                        NULL, 0);
  wUsername = ALLOCV_N(WCHAR, vusernameBuf, len + 1);
  MultiByteToWideChar(CP_UTF8, 0,
                      RSTRING_PTR(rb_username), RSTRING_LEN(rb_username),
                      wUsername, len);
  wUsername[len] = L'\0';

  if (winevtSession->username)
    free(winevtSession->username);
  winevtSession->username = _wcsdup(wUsername);

  ALLOCV_END(vusernameBuf);

  return Qnil;
}