vacman_controller 0.5.0 → 0.6.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/ext/vacman_controller/dpx.c +73 -0
- data/ext/vacman_controller/extconf.rb +1 -1
- data/ext/vacman_controller/kernel.c +97 -0
- data/ext/vacman_controller/main.c +90 -0
- data/ext/vacman_controller/serialize.c +84 -0
- data/ext/vacman_controller/token.c +207 -0
- data/ext/vacman_controller/vacman_controller.h +53 -0
- data/lib/vacman_controller/token/properties.rb +87 -33
- data/lib/vacman_controller/token.rb +7 -7
- data/lib/vacman_controller/version.rb +3 -0
- data/lib/vacman_controller.rb +1 -4
- metadata +36 -2
- data/ext/vacman_controller/low_level.c +0 -530
@@ -1,530 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
* Vacman Controller wrapper
|
3
|
-
*
|
4
|
-
* This Ruby Extension wraps the VASCO Vacman Controller
|
5
|
-
* library and makes its API accessible to Ruby code.
|
6
|
-
*
|
7
|
-
* (C) 2013 https://github.com/mlankenau
|
8
|
-
* (C) 2019 m.barnaba@ifad.org
|
9
|
-
*/
|
10
|
-
|
11
|
-
#include <ruby.h>
|
12
|
-
#include <string.h>
|
13
|
-
#include <aal2sdk.h>
|
14
|
-
|
15
|
-
|
16
|
-
/* The Vacman default kernel parameters, set up upon extension initialisation. */
|
17
|
-
TKernelParms g_KernelParms;
|
18
|
-
|
19
|
-
/* Ruby exception type, defined as VacmanController::Error in Ruby land. */
|
20
|
-
static VALUE e_VacmanError;
|
21
|
-
|
22
|
-
|
23
|
-
/*
|
24
|
-
* Raises an Error, decoding the Vacman Controller error code.
|
25
|
-
*/
|
26
|
-
static void vacman_library_error(const char* method, int vacman_error_code) {
|
27
|
-
aat_ascii vacman_error_message[100]; // Recommended value in documentation.
|
28
|
-
|
29
|
-
AAL2GetErrorMsg(vacman_error_code, vacman_error_message);
|
30
|
-
|
31
|
-
char error_message[256];
|
32
|
-
snprintf(error_message, 255, "%s error %d: %s", method, vacman_error_code,
|
33
|
-
vacman_error_message);
|
34
|
-
|
35
|
-
VALUE exc = rb_exc_new2(e_VacmanError, error_message);
|
36
|
-
rb_iv_set(exc, "@library_method", rb_str_new2(method));
|
37
|
-
rb_iv_set(exc, "@error_code", INT2FIX(vacman_error_code));
|
38
|
-
rb_iv_set(exc, "@error_message", rb_str_new2(vacman_error_message));
|
39
|
-
|
40
|
-
rb_exc_raise(exc);
|
41
|
-
}
|
42
|
-
|
43
|
-
|
44
|
-
/*
|
45
|
-
* Use AAL2GetLibraryVersion to obtain library version and return it as a Ruby Hash
|
46
|
-
*/
|
47
|
-
static VALUE vacman_library_version(VALUE module) {
|
48
|
-
aat_ascii version[16];
|
49
|
-
aat_int32 version_len = sizeof(version);
|
50
|
-
|
51
|
-
aat_ascii bitness[4];
|
52
|
-
aat_int32 bitness_len = sizeof(bitness);
|
53
|
-
|
54
|
-
aat_ascii type[8];
|
55
|
-
aat_int32 type_len = sizeof(type);
|
56
|
-
|
57
|
-
aat_int32 result = AAL2GetLibraryVersion(version, &version_len, bitness,
|
58
|
-
&bitness_len, type, &type_len);
|
59
|
-
|
60
|
-
if (result != 0) {
|
61
|
-
vacman_library_error("AAL2GetLibraryVersion", result);
|
62
|
-
return Qnil;
|
63
|
-
}
|
64
|
-
|
65
|
-
VALUE hash = rb_hash_new();
|
66
|
-
rb_hash_aset(hash, rb_str_new2("version"), rb_str_new2(version));
|
67
|
-
rb_hash_aset(hash, rb_str_new2("bitness"), rb_str_new2(bitness));
|
68
|
-
rb_hash_aset(hash, rb_str_new2("type"), rb_str_new2(type));
|
69
|
-
|
70
|
-
return hash;
|
71
|
-
}
|
72
|
-
|
73
|
-
|
74
|
-
/*
|
75
|
-
* Convert a TDigipassBlob structure into a Ruby Hash
|
76
|
-
*/
|
77
|
-
static void digipass_to_rbhash(TDigipassBlob* dpdata, VALUE hash) {
|
78
|
-
char buffer[256];
|
79
|
-
|
80
|
-
memset(buffer, 0, sizeof(buffer));
|
81
|
-
strncpy(buffer, dpdata->Serial, 10);
|
82
|
-
rb_hash_aset(hash, rb_str_new2("serial"), rb_str_new2(buffer));
|
83
|
-
|
84
|
-
memset(buffer, 0, sizeof(buffer));
|
85
|
-
strncpy(buffer, dpdata->AppName, 12);
|
86
|
-
rb_hash_aset(hash, rb_str_new2("app_name"), rb_str_new2(buffer));
|
87
|
-
|
88
|
-
memset(buffer, 0, sizeof(buffer));
|
89
|
-
strncpy(buffer, dpdata->Blob, 224);
|
90
|
-
rb_hash_aset(hash, rb_str_new2("blob"), rb_str_new2(buffer));
|
91
|
-
|
92
|
-
rb_hash_aset(hash, rb_str_new2("flags1"), rb_fix_new(dpdata->DPFlags[0]));
|
93
|
-
rb_hash_aset(hash, rb_str_new2("flags2"), rb_fix_new(dpdata->DPFlags[1]));
|
94
|
-
}
|
95
|
-
|
96
|
-
|
97
|
-
/*
|
98
|
-
* Gets the given property from the given token hash and raises an Error
|
99
|
-
* if the following conditions occur:
|
100
|
-
*
|
101
|
-
* * The key is not found
|
102
|
-
* * The key is not of the given type
|
103
|
-
*
|
104
|
-
* Otherwise, the value corresponding to the key is returned.
|
105
|
-
*
|
106
|
-
*/
|
107
|
-
static VALUE rbhash_get_key(VALUE token, const char *property, int type) {
|
108
|
-
VALUE ret = rb_hash_aref(token, rb_str_new2(property));
|
109
|
-
|
110
|
-
if (ret == Qnil) {
|
111
|
-
rb_raise(e_VacmanError, "invalid token object given: %s property is nil", property);
|
112
|
-
return Qnil;
|
113
|
-
}
|
114
|
-
|
115
|
-
if (!RB_TYPE_P(ret, type)) {
|
116
|
-
rb_raise(e_VacmanError, "invalid token object given: %s property is not of the correct type", property);
|
117
|
-
return Qnil;
|
118
|
-
}
|
119
|
-
|
120
|
-
return ret;
|
121
|
-
}
|
122
|
-
|
123
|
-
|
124
|
-
/*
|
125
|
-
* Convert a Ruby Hash with the required keys to a TDigipassBlob structure.
|
126
|
-
*/
|
127
|
-
static void rbhash_to_digipass(VALUE token, TDigipassBlob* dpdata) {
|
128
|
-
if (!RB_TYPE_P(token, T_HASH)) {
|
129
|
-
rb_raise(e_VacmanError, "invalid token object given, requires an hash");
|
130
|
-
return;
|
131
|
-
}
|
132
|
-
|
133
|
-
VALUE blob = rbhash_get_key(token, "blob", T_STRING);
|
134
|
-
VALUE serial = rbhash_get_key(token, "serial", T_STRING);
|
135
|
-
VALUE app_name = rbhash_get_key(token, "app_name", T_STRING);
|
136
|
-
VALUE flag1 = rbhash_get_key(token, "flags1", T_FIXNUM);
|
137
|
-
VALUE flag2 = rbhash_get_key(token, "flags2", T_FIXNUM);
|
138
|
-
|
139
|
-
memset(dpdata, 0, sizeof(*dpdata));
|
140
|
-
|
141
|
-
strcpy(dpdata->Blob, rb_string_value_cstr(&blob));
|
142
|
-
strncpy(dpdata->Serial, rb_string_value_cstr(&serial), sizeof(dpdata->Serial));
|
143
|
-
strncpy(dpdata->AppName, rb_string_value_cstr(&app_name), sizeof(dpdata->AppName));
|
144
|
-
dpdata->DPFlags[0] = rb_fix2int(flag1);
|
145
|
-
dpdata->DPFlags[1] = rb_fix2int(flag2);
|
146
|
-
}
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
/*
|
151
|
-
* Generate an OTP from the given token, if the token allows it.
|
152
|
-
*/
|
153
|
-
static VALUE vacman_generate_password(VALUE module, VALUE token) {
|
154
|
-
TDigipassBlob dpdata;
|
155
|
-
|
156
|
-
rbhash_to_digipass(token, &dpdata);
|
157
|
-
|
158
|
-
aat_ascii password[18];
|
159
|
-
memset(password, 0, sizeof(password));
|
160
|
-
|
161
|
-
aat_int32 result = AAL2GenPassword(&dpdata, &g_KernelParms, password, NULL);
|
162
|
-
digipass_to_rbhash(&dpdata, token);
|
163
|
-
|
164
|
-
if (result != 0) {
|
165
|
-
vacman_library_error("AAL2GenPassword", result);
|
166
|
-
return Qnil;
|
167
|
-
}
|
168
|
-
|
169
|
-
return rb_str_new2(password);
|
170
|
-
}
|
171
|
-
|
172
|
-
|
173
|
-
/*
|
174
|
-
* Vacman properties names and IDs registry
|
175
|
-
*/
|
176
|
-
struct token_property {
|
177
|
-
const char *name;
|
178
|
-
aat_int32 id;
|
179
|
-
};
|
180
|
-
static struct token_property token_properties[] = {
|
181
|
-
{"token_model", TOKEN_MODEL },
|
182
|
-
{"token_status", TOKEN_STATUS },
|
183
|
-
{"use_count", USE_COUNT },
|
184
|
-
{"last_time_used", LAST_TIME_USED },
|
185
|
-
{"last_time_shift", LAST_TIME_SHIFT },
|
186
|
-
{"time_based_algo", TIME_BASED_ALGO },
|
187
|
-
{"event_based_algo", EVENT_BASED_ALGO },
|
188
|
-
{"pin_supported", PIN_SUPPORTED },
|
189
|
-
{"unlock_supported", UNLOCK_SUPPORTED },
|
190
|
-
{"pin_ch_on", PIN_CH_ON },
|
191
|
-
{"pin_change_enabled", PIN_CH_ON },
|
192
|
-
{"pin_len", PIN_LEN },
|
193
|
-
{"pin_length", PIN_LEN },
|
194
|
-
{"pin_min_len", PIN_MIN_LEN },
|
195
|
-
{"pin_minimum_length", PIN_MIN_LEN },
|
196
|
-
{"pin_enabled", PIN_ENABLED },
|
197
|
-
{"pin_ch_forced", PIN_CH_FORCED },
|
198
|
-
{"pin_change_forced", PIN_CH_FORCED },
|
199
|
-
{"virtual_token_type", VIRTUAL_TOKEN_TYPE },
|
200
|
-
{"virtual_token_grace_period", VIRTUAL_TOKEN_GRACE_PERIOD },
|
201
|
-
{"virtual_token_remain_use", VIRTUAL_TOKEN_REMAIN_USE },
|
202
|
-
{"last_response_type", LAST_RESPONSE_TYPE },
|
203
|
-
{"error_count", ERROR_COUNT },
|
204
|
-
{"event_value", EVENT_VALUE },
|
205
|
-
{"last_event_value", LAST_EVENT_VALUE },
|
206
|
-
{"sync_windows", SYNC_WINDOWS },
|
207
|
-
{"primary_token_enabled", PRIMARY_TOKEN_ENABLED },
|
208
|
-
{"virtual_token_supported", VIRTUAL_TOKEN_SUPPORTED },
|
209
|
-
{"virtual_token_enabled", VIRTUAL_TOKEN_ENABLED },
|
210
|
-
{"code_word", CODE_WORD },
|
211
|
-
{"auth_mode", AUTH_MODE },
|
212
|
-
{"ocra_suite", OCRA_SUITE },
|
213
|
-
{"derivation_supported", DERIVATION_SUPPORTED },
|
214
|
-
{"max_dtf_number", MAX_DTF_NUMBER },
|
215
|
-
{"response_len", RESPONSE_LEN },
|
216
|
-
{"response_length", RESPONSE_LEN },
|
217
|
-
{"response_format", RESPONSE_FORMAT },
|
218
|
-
{"response_chk", RESPONSE_CHK },
|
219
|
-
{"response_checksum", RESPONSE_CHK },
|
220
|
-
{"time_step", TIME_STEP },
|
221
|
-
{"use_3des", TRIPLE_DES_USED },
|
222
|
-
{"triple_des_used", TRIPLE_DES_USED },
|
223
|
-
};
|
224
|
-
|
225
|
-
static size_t token_properties_count = sizeof(token_properties)/sizeof(struct token_property);
|
226
|
-
|
227
|
-
/*
|
228
|
-
* Convert property name to property ID
|
229
|
-
*/
|
230
|
-
static long vacman_get_property_id(char *property_name) {
|
231
|
-
for (size_t i = 0; i < token_properties_count; i++) {
|
232
|
-
if (strcmp(property_name, token_properties[i].name) == 0) {
|
233
|
-
return token_properties[i].id;
|
234
|
-
}
|
235
|
-
}
|
236
|
-
|
237
|
-
rb_raise(e_VacmanError, "Invalid property name `%s'", property_name);
|
238
|
-
return 0;
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
/*
|
243
|
-
* Get token property names
|
244
|
-
*/
|
245
|
-
static VALUE vacman_get_token_property_names(void) {
|
246
|
-
VALUE ret = rb_ary_new();
|
247
|
-
|
248
|
-
for (size_t i = 0; i < token_properties_count; i++) {
|
249
|
-
const char *name = token_properties[i].name;
|
250
|
-
rb_ary_push(ret, rb_str_new2(name));
|
251
|
-
}
|
252
|
-
|
253
|
-
return ret;
|
254
|
-
}
|
255
|
-
|
256
|
-
|
257
|
-
/*
|
258
|
-
* Get the given property value from the given token.
|
259
|
-
*/
|
260
|
-
static VALUE vacman_get_token_property(VALUE module, VALUE token, VALUE property) {
|
261
|
-
TDigipassBlob dpdata;
|
262
|
-
rbhash_to_digipass(token, &dpdata);
|
263
|
-
|
264
|
-
aat_ascii value[64];
|
265
|
-
aat_int32 property_id = vacman_get_property_id(StringValueCStr(property));
|
266
|
-
aat_int32 result = AAL2GetTokenProperty(&dpdata, &g_KernelParms, property_id, value);
|
267
|
-
|
268
|
-
if (result == 0) {
|
269
|
-
return rb_str_new2(value);
|
270
|
-
} else {
|
271
|
-
vacman_library_error("AAL2GetTokenProperty", result);
|
272
|
-
return Qnil;
|
273
|
-
}
|
274
|
-
}
|
275
|
-
|
276
|
-
|
277
|
-
/*
|
278
|
-
* Set the given token property to the given value.
|
279
|
-
*/
|
280
|
-
static VALUE vacman_set_token_property(VALUE module, VALUE token, VALUE property, VALUE rbval) {
|
281
|
-
TDigipassBlob dpdata;
|
282
|
-
|
283
|
-
aat_int32 property_id = vacman_get_property_id(StringValueCStr(property));
|
284
|
-
aat_int32 value = rb_fix2int(rbval);
|
285
|
-
|
286
|
-
rbhash_to_digipass(token, &dpdata);
|
287
|
-
|
288
|
-
aat_int32 result = AAL2SetTokenProperty(&dpdata, &g_KernelParms, property_id, value);
|
289
|
-
|
290
|
-
digipass_to_rbhash(&dpdata, token);
|
291
|
-
|
292
|
-
if (result == 0) {
|
293
|
-
return Qtrue;
|
294
|
-
} else {
|
295
|
-
vacman_library_error("AAL2SetTokenProperty", result);
|
296
|
-
return Qnil;
|
297
|
-
}
|
298
|
-
}
|
299
|
-
|
300
|
-
|
301
|
-
/*
|
302
|
-
* Changes the static password on the given token.
|
303
|
-
*/
|
304
|
-
static VALUE vacman_set_token_pin(VALUE module, VALUE token, VALUE pin) {
|
305
|
-
TDigipassBlob dpdata;
|
306
|
-
|
307
|
-
if (!RB_TYPE_P(pin, T_STRING)) {
|
308
|
-
rb_raise(e_VacmanError, "invalid pin given, requires a string");
|
309
|
-
return Qnil;
|
310
|
-
}
|
311
|
-
|
312
|
-
rbhash_to_digipass(token, &dpdata);
|
313
|
-
|
314
|
-
aat_ascii *passwd = StringValueCStr(pin);
|
315
|
-
aat_int32 result = AAL2ChangeStaticPassword(&dpdata, &g_KernelParms, passwd, passwd);
|
316
|
-
|
317
|
-
digipass_to_rbhash(&dpdata, token);
|
318
|
-
|
319
|
-
if (result == 0) {
|
320
|
-
return Qtrue;
|
321
|
-
} else {
|
322
|
-
vacman_library_error("AAL2ChangeStaticPassword", result);
|
323
|
-
return Qnil;
|
324
|
-
}
|
325
|
-
}
|
326
|
-
|
327
|
-
|
328
|
-
/*
|
329
|
-
* Verifies the given OTP against the given token.
|
330
|
-
*/
|
331
|
-
static VALUE vacman_verify_password(VALUE module, VALUE token, VALUE password) {
|
332
|
-
TDigipassBlob dpdata;
|
333
|
-
|
334
|
-
rbhash_to_digipass(token, &dpdata);
|
335
|
-
|
336
|
-
aat_int32 result = AAL2VerifyPassword(&dpdata, &g_KernelParms, rb_string_value_cstr(&password), 0);
|
337
|
-
|
338
|
-
digipass_to_rbhash(&dpdata, token);
|
339
|
-
|
340
|
-
if (result == 0)
|
341
|
-
return Qtrue;
|
342
|
-
else {
|
343
|
-
vacman_library_error("AAL2VerifyPassword", result);
|
344
|
-
return Qnil;
|
345
|
-
}
|
346
|
-
}
|
347
|
-
|
348
|
-
|
349
|
-
/*
|
350
|
-
* Imports a .DPX file containing token seeds and initialisation values.
|
351
|
-
*
|
352
|
-
* Pass the pre-shared key to validate it as the second argument. The
|
353
|
-
* key is not validated by the AAL2 library, if you pass a different
|
354
|
-
* key than the one that was used to create the DPX, you will get back
|
355
|
-
* tokens that generate different OTPs.
|
356
|
-
*
|
357
|
-
*/
|
358
|
-
static VALUE vacman_import(VALUE module, VALUE filename, VALUE key) {
|
359
|
-
TDPXHandle dpx_handle;
|
360
|
-
aat_int16 appl_count;
|
361
|
-
aat_ascii appl_names[13*8];
|
362
|
-
aat_int16 token_count;
|
363
|
-
|
364
|
-
aat_int32 result = AAL2DPXInit(&dpx_handle,
|
365
|
-
rb_string_value_cstr(&filename),
|
366
|
-
rb_string_value_cstr(&key),
|
367
|
-
&appl_count,
|
368
|
-
appl_names,
|
369
|
-
&token_count);
|
370
|
-
|
371
|
-
if (result != 0) {
|
372
|
-
vacman_library_error("AAL2DPXInit", result);
|
373
|
-
return Qnil;
|
374
|
-
}
|
375
|
-
|
376
|
-
aat_ascii sw_out_serial_No[22+1];
|
377
|
-
aat_ascii sw_out_type[5+1];
|
378
|
-
aat_ascii sw_out_authmode[2+1];
|
379
|
-
TDigipassBlob dpdata;
|
380
|
-
|
381
|
-
VALUE list = rb_ary_new();
|
382
|
-
|
383
|
-
while (1) {
|
384
|
-
result = AAL2DPXGetToken(&dpx_handle,
|
385
|
-
&g_KernelParms,
|
386
|
-
appl_names,
|
387
|
-
sw_out_serial_No,
|
388
|
-
sw_out_type,
|
389
|
-
sw_out_authmode,
|
390
|
-
&dpdata);
|
391
|
-
|
392
|
-
|
393
|
-
if (result < 0) {
|
394
|
-
vacman_library_error("AAL2DPXGetToken", result);
|
395
|
-
return Qnil;
|
396
|
-
}
|
397
|
-
|
398
|
-
if (result == 107) break;
|
399
|
-
|
400
|
-
VALUE hash = rb_hash_new();
|
401
|
-
|
402
|
-
digipass_to_rbhash(&dpdata, hash);
|
403
|
-
|
404
|
-
rb_ary_push(list, hash);
|
405
|
-
}
|
406
|
-
|
407
|
-
AAL2DPXClose(&dpx_handle);
|
408
|
-
|
409
|
-
return list;
|
410
|
-
}
|
411
|
-
|
412
|
-
|
413
|
-
/*
|
414
|
-
* Vacman Controller kernel properties
|
415
|
-
*/
|
416
|
-
struct kernel_property {
|
417
|
-
const char *name;
|
418
|
-
aat_int32 *value;
|
419
|
-
aat_int32 deflt;
|
420
|
-
};
|
421
|
-
static struct kernel_property kernel_properties[] = {
|
422
|
-
{ "ITimeWindow", &g_KernelParms.ITimeWindow, 30 }, // Identification Window size in time steps
|
423
|
-
{ "STimeWindow", &g_KernelParms.STimeWindow, 24 }, // Signature Window size in secs
|
424
|
-
{ "DiagLevel", &g_KernelParms.DiagLevel, 0 }, // Requested Diagnostic Level
|
425
|
-
{ "GMTAdjust", &g_KernelParms.GMTAdjust, 0 }, // GMT Time adjustment to perform
|
426
|
-
{ "CheckChallenge", &g_KernelParms.CheckChallenge, 0 }, // Verify Challenge Corrupted (mandatory for Gordian)
|
427
|
-
{ "IThreshold", &g_KernelParms.IThreshold, 3 }, // Identification Error Threshold
|
428
|
-
{ "SThreshold", &g_KernelParms.SThreshold, 1 }, // Signature Error Threshold
|
429
|
-
{ "ChkInactDays", &g_KernelParms.ChkInactDays, 0 }, // Check Inactive Days
|
430
|
-
{ "DeriveVector", &g_KernelParms.DeriveVector, 0 }, // Vector used to make Data Encryption unique
|
431
|
-
{ "SyncWindow", &g_KernelParms.SyncWindow, 2 }, // Synchronisation Time Window (h)
|
432
|
-
{ "OnLineSG", &g_KernelParms.OnLineSG, 2 }, // On line signature
|
433
|
-
{ "EventWindow", &g_KernelParms.EventWindow, 100 }, // Event Window size in nbr of iterations
|
434
|
-
{ "HSMSlotId", &g_KernelParms.HSMSlotId, 0 }, // HSM Slot id uses to store DB and Transport Key
|
435
|
-
};
|
436
|
-
static size_t kernel_properties_count = sizeof(kernel_properties)/sizeof(struct kernel_property);
|
437
|
-
|
438
|
-
/*
|
439
|
-
* Initialise the kernel parameters with their defaults
|
440
|
-
*/
|
441
|
-
static void vacman_init_kernel_params() {
|
442
|
-
memset(&g_KernelParms, 0, sizeof(g_KernelParms));
|
443
|
-
|
444
|
-
g_KernelParms.ParmCount = 19; /* Number of valid parameters in this list */
|
445
|
-
|
446
|
-
for (size_t i = 0; i < kernel_properties_count; i++) {
|
447
|
-
*kernel_properties[i].value = kernel_properties[i].deflt;
|
448
|
-
}
|
449
|
-
}
|
450
|
-
|
451
|
-
|
452
|
-
/*
|
453
|
-
* Get kernel parameter names
|
454
|
-
*/
|
455
|
-
static VALUE vacman_get_kernel_property_names(void) {
|
456
|
-
VALUE ret = rb_ary_new();
|
457
|
-
|
458
|
-
for (size_t i = 0; i < kernel_properties_count; i++) {
|
459
|
-
const char *name = kernel_properties[i].name;
|
460
|
-
rb_ary_push(ret, rb_str_new2(name));
|
461
|
-
}
|
462
|
-
|
463
|
-
return ret;
|
464
|
-
}
|
465
|
-
|
466
|
-
|
467
|
-
/*
|
468
|
-
* Set kernel parameter
|
469
|
-
*/
|
470
|
-
static VALUE vacman_set_kernel_param(VALUE module, VALUE paramname, VALUE rbval) {
|
471
|
-
char *name = StringValueCStr(paramname);
|
472
|
-
int value = rb_fix2int(rbval);
|
473
|
-
|
474
|
-
for (size_t i = 0; i < kernel_properties_count; i++) {
|
475
|
-
if (strcmp(name, kernel_properties[i].name) == 0) {
|
476
|
-
*kernel_properties[i].value = value;
|
477
|
-
return Qtrue;
|
478
|
-
}
|
479
|
-
}
|
480
|
-
|
481
|
-
rb_raise(e_VacmanError, "Invalid kernel param %s", name);
|
482
|
-
return Qnil;
|
483
|
-
}
|
484
|
-
|
485
|
-
|
486
|
-
/*
|
487
|
-
* Get kernel parameter
|
488
|
-
*/
|
489
|
-
static VALUE vacman_get_kernel_param(VALUE module, VALUE paramname) {
|
490
|
-
char *name = StringValueCStr(paramname);
|
491
|
-
|
492
|
-
for (size_t i = 0; i < kernel_properties_count; i++) {
|
493
|
-
if (strcmp(name, kernel_properties[i].name) == 0) {
|
494
|
-
return LONG2FIX(*kernel_properties[i].value);
|
495
|
-
}
|
496
|
-
}
|
497
|
-
|
498
|
-
rb_raise(e_VacmanError, "Invalid kernel param %s", name);
|
499
|
-
return Qnil;
|
500
|
-
}
|
501
|
-
|
502
|
-
|
503
|
-
/*
|
504
|
-
* Extension entry point
|
505
|
-
*/
|
506
|
-
void Init_low_level(void) {
|
507
|
-
VALUE controller = rb_define_module("VacmanController");
|
508
|
-
VALUE lowlevel = rb_define_module_under(controller, "LowLevel");
|
509
|
-
|
510
|
-
e_VacmanError = rb_define_class_under(controller, "Error", rb_eStandardError);
|
511
|
-
|
512
|
-
vacman_init_kernel_params();
|
513
|
-
|
514
|
-
/* Global methods */
|
515
|
-
rb_define_singleton_method(lowlevel, "library_version", vacman_library_version, 0);
|
516
|
-
rb_define_singleton_method(lowlevel, "import", vacman_import, 2);
|
517
|
-
|
518
|
-
/* Token methods */
|
519
|
-
rb_define_singleton_method(lowlevel, "token_property_names", vacman_get_token_property_names, 0);
|
520
|
-
rb_define_singleton_method(lowlevel, "get_token_property", vacman_get_token_property, 2);
|
521
|
-
rb_define_singleton_method(lowlevel, "set_token_property", vacman_set_token_property, 3);
|
522
|
-
rb_define_singleton_method(lowlevel, "generate_password", vacman_generate_password, 1);
|
523
|
-
rb_define_singleton_method(lowlevel, "verify_password", vacman_verify_password, 2);
|
524
|
-
rb_define_singleton_method(lowlevel, "set_token_pin", vacman_set_token_pin, 2);
|
525
|
-
|
526
|
-
/* Kernel methods */
|
527
|
-
rb_define_singleton_method(lowlevel, "kernel_property_names", vacman_get_kernel_property_names, 0);
|
528
|
-
rb_define_singleton_method(lowlevel, "get_kernel_param", vacman_get_kernel_param, 1);
|
529
|
-
rb_define_singleton_method(lowlevel, "set_kernel_param", vacman_set_kernel_param, 2);
|
530
|
-
}
|