passdb_slim_config.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560
  1. #include "passdb_slim.h"
  2. // SHALLOW COPY
  3. // passdb_slim_config is a shallow container. All memory management
  4. // should be done from ctx.
  5. //
  6. void passdb_slim_copy_config( passdb_slim_config *cfg, passdb_slim_context *ctx )
  7. {
  8. cfg->hash_modulus = ctx->hash_modulus;
  9. cfg->n_one_cred_bank = ctx->n_one_cred_bank;
  10. cfg->n_two_cred_bank = ctx->n_two_cred_bank;
  11. cfg->n_spillover_bank = ctx->n_spillover_bank;
  12. cfg->n_one_cred_bank_size = ctx->n_one_cred_bank_size;
  13. cfg->n_two_cred_bank_size = ctx->n_two_cred_bank_size;
  14. cfg->n_spillover_bank_size = ctx->n_spillover_bank_size;
  15. cfg->n_one_cred_max_bank = ctx->n_one_cred_max_bank;
  16. cfg->n_two_cred_max_bank = ctx->n_two_cred_max_bank;
  17. cfg->n_spillover_max_bank = ctx->n_spillover_max_bank;
  18. cfg->one_cred_db_base_fn = ctx->one_cred_db_base_fn;
  19. cfg->two_cred_db_base_fn = ctx->two_cred_db_base_fn;
  20. cfg->spillover_db_base_fn = ctx->spillover_db_base_fn;
  21. cfg->db_fn_suffix = ctx->db_fn_suffix;
  22. cfg->ruleparam_db_fn = ctx->ruleparam_db_fn;
  23. cfg->high_watermark_threshold = ctx->high_watermark_threshold;
  24. cfg->low_watermark_threshold = ctx->low_watermark_threshold;
  25. }
  26. #define DEFAULT_HASH_MODULUS 131101
  27. #define DEFAULT_ONE_CRED_MAX_BANK 25
  28. #define DEFAULT_TWO_CRED_MAX_BANK 25
  29. #define DEFAULT_SPILLOVER_MAX_BANK 25
  30. #define DEFAULT_ONE_CRED_BANK_SIZE 10012
  31. #define DEFAULT_TWO_CRED_BANK_SIZE 10012
  32. #define DEFAULT_SPILLOVER_BANK_SIZE 32
  33. #define DEFAULT_ONE_CRED_BANK 1
  34. #define DEFAULT_TWO_CRED_BANK 1
  35. #define DEFAULT_SPILLOVER_BANK 1
  36. #define DEFAULT_ONE_CRED_DB_BASE DATABASE_FILE_PATH "passes_one_bank"
  37. #define DEFAULT_TWO_CRED_DB_BASE DATABASE_FILE_PATH "passes_two_bank"
  38. #define DEFAULT_SPILLOVER_DB_BASE DATABASE_FILE_PATH "passes_spillover_bank"
  39. #define DEFAULT_DB_SUFFIX ".mem"
  40. #define DEFAULT_RULEPARAM_DB DATABASE_FILE_PATH "ruleparam.db"
  41. #define DEFAULT_HIGH_WATERMARK 0.95
  42. //unused
  43. //
  44. #define DEFAULT_LOW_WATERMARK 0.25
  45. int make_default_config( char *config_fn )
  46. {
  47. FILE *fp;
  48. struct tm tm_tim;
  49. struct timeval timval;
  50. char str_tim[FN_SZ];
  51. gettimeofday(&timval, NULL);
  52. localtime_r(&(timval.tv_sec), &tm_tim);
  53. asctime_r(&tm_tim, str_tim);
  54. fp = fopen(config_fn, "w");
  55. if (!fp)
  56. return -1;
  57. fprintf(fp, "# %s", str_tim );
  58. fprintf(fp, "#\n");
  59. fprintf(fp, "#\n");
  60. fprintf(fp, "hash_modulus %i\n", DEFAULT_HASH_MODULUS);
  61. fprintf(fp, "\n");
  62. fprintf(fp, "n_one_cred_max_bank %i\n", DEFAULT_ONE_CRED_MAX_BANK );
  63. fprintf(fp, "n_two_cred_max_bank %i\n", DEFAULT_TWO_CRED_MAX_BANK );
  64. fprintf(fp, "n_spillover_max_bank %i\n", DEFAULT_SPILLOVER_MAX_BANK );
  65. fprintf(fp, "\n");
  66. fprintf(fp, "n_one_cred_bank_size %i\n", DEFAULT_ONE_CRED_BANK_SIZE );
  67. fprintf(fp, "n_two_cred_bank_size %i\n", DEFAULT_TWO_CRED_BANK_SIZE );
  68. fprintf(fp, "n_spillover_bank_size %i\n", DEFAULT_SPILLOVER_BANK_SIZE );
  69. fprintf(fp, "\n");
  70. fprintf(fp, "n_one_cred_bank %i\n", DEFAULT_ONE_CRED_BANK );
  71. fprintf(fp, "n_two_cred_bank %i\n", DEFAULT_TWO_CRED_BANK );
  72. fprintf(fp, "n_spillover_bank %i\n", DEFAULT_SPILLOVER_BANK );
  73. fprintf(fp, "\n");
  74. fprintf(fp, "one_cred_db_base %s\n", DEFAULT_ONE_CRED_DB_BASE );
  75. fprintf(fp, "two_cred_db_base %s\n", DEFAULT_TWO_CRED_DB_BASE );
  76. fprintf(fp, "spillover_db_base %s\n", DEFAULT_SPILLOVER_DB_BASE );
  77. fprintf(fp, "\n");
  78. fprintf(fp, "db_suffix %s\n", DEFAULT_DB_SUFFIX );
  79. fprintf(fp, "\n");
  80. fprintf(fp, "ruleparam_db %s\n", DEFAULT_RULEPARAM_DB );
  81. fprintf(fp, "\n");
  82. fprintf(fp, "high_watermark_threshold %f\n", DEFAULT_HIGH_WATERMARK );
  83. fprintf(fp, "low_watermark_threshold %f\n", DEFAULT_LOW_WATERMARK );
  84. fprintf(fp, "\n");
  85. fclose(fp);
  86. return 0;
  87. }
  88. int save_config( passdb_slim_config *cfg, char *config_fn )
  89. {
  90. FILE *fp;
  91. struct tm tm_tim;
  92. struct timeval timval;
  93. char str_tim[FN_SZ];
  94. gettimeofday(&timval, NULL);
  95. localtime_r(&(timval.tv_sec), &tm_tim);
  96. asctime_r(&tm_tim, str_tim);
  97. fp = fopen( config_fn, "w" );
  98. if (!fp)
  99. {
  100. //DEBUG
  101. //fprintf(stderr, "ERROR: passdb.save_config: could not open file %s\n", config_fn);
  102. //exit(1);
  103. perror(config_fn);
  104. return -1;
  105. }
  106. fprintf(fp, "# %s", str_tim );
  107. fprintf(fp, "#\n");
  108. fprintf(fp, "#\n");
  109. fprintf(fp, "hash_modulus %i\n", cfg->hash_modulus);
  110. fprintf(fp, "\n");
  111. fprintf(fp, "n_one_cred_max_bank %i\n", cfg->n_one_cred_max_bank);
  112. fprintf(fp, "n_two_cred_max_bank %i\n", cfg->n_two_cred_max_bank);
  113. fprintf(fp, "n_spillover_max_bank %i\n", cfg->n_spillover_max_bank);
  114. fprintf(fp, "\n");
  115. fprintf(fp, "n_one_cred_bank_size %i\n", cfg->n_one_cred_bank_size);
  116. fprintf(fp, "n_two_cred_bank_size %i\n", cfg->n_two_cred_bank_size);
  117. fprintf(fp, "n_spillover_bank_size %i\n", cfg->n_spillover_bank_size);
  118. fprintf(fp, "\n");
  119. fprintf(fp, "n_one_cred_bank %i\n", cfg->n_one_cred_bank);
  120. fprintf(fp, "n_two_cred_bank %i\n", cfg->n_two_cred_bank);
  121. fprintf(fp, "n_spillover_bank %i\n", cfg->n_spillover_bank);
  122. fprintf(fp, "\n");
  123. fprintf(fp, "one_cred_db_base %s\n", cfg->one_cred_db_base_fn);
  124. fprintf(fp, "two_cred_db_base %s\n", cfg->two_cred_db_base_fn);
  125. fprintf(fp, "spillover_db_base %s\n", cfg->spillover_db_base_fn);
  126. fprintf(fp, "\n");
  127. fprintf(fp, "db_suffix %s\n", cfg->db_fn_suffix);
  128. fprintf(fp, "\n");
  129. fprintf(fp, "ruleparam_db %s\n", cfg->ruleparam_db_fn);
  130. fprintf(fp, "\n");
  131. fprintf(fp, "high_watermark_threshold %f\n", (double)cfg->high_watermark_threshold );
  132. fprintf(fp, "low_watermark_threshold %f\n", (double)cfg->low_watermark_threshold );
  133. fprintf(fp, "\n");
  134. fclose(fp);
  135. return 0;
  136. }
  137. int read_config( passdb_slim_config *cfg, char *config_fn )
  138. {
  139. FILE *fp;
  140. char buf[FN_SZ];
  141. char keyword[FN_SZ], rvalue[FN_SZ];
  142. int r;
  143. cfg->hash_modulus = -1;
  144. cfg->n_one_cred_bank_size = -1;
  145. cfg->n_two_cred_bank_size = -1;
  146. cfg->n_spillover_bank_size = -1;
  147. cfg->n_one_cred_bank = -1;
  148. cfg->n_two_cred_bank = -1;
  149. cfg->n_spillover_bank = -1;
  150. cfg->one_cred_db_base_fn = NULL;
  151. cfg->two_cred_db_base_fn = NULL;
  152. cfg->spillover_db_base_fn = NULL;
  153. cfg->db_fn_suffix = NULL;
  154. cfg->high_watermark_threshold = 0.99;
  155. cfg->low_watermark_threshold = 0.1;
  156. cfg->ruleparam_db_fn = NULL;
  157. fp = fopen(config_fn, "r");
  158. if (!fp)
  159. return -1;
  160. while ( fgets(buf, FN_SZ-1, fp) )
  161. {
  162. if (buf[0] == '#')
  163. continue;
  164. r = sscanf(buf, "%s %s", keyword, rvalue);
  165. if (keyword[0] == '#')
  166. continue;
  167. if (r!=2)
  168. continue;
  169. if ( strncmp(keyword, "hash_modulus", FN_SZ-1) == 0 )
  170. {
  171. cfg->hash_modulus = atoi(rvalue);
  172. }
  173. else if (strncmp(keyword, "n_one_cred_bank_size", FN_SZ-1) == 0 )
  174. {
  175. cfg->n_one_cred_bank_size = atoi(rvalue);
  176. }
  177. else if (strncmp(keyword, "n_two_cred_bank_size", FN_SZ-1) == 0 )
  178. {
  179. cfg->n_two_cred_bank_size = atoi(rvalue);
  180. }
  181. else if (strncmp(keyword, "n_spillover_bank_size", FN_SZ-1) == 0 )
  182. {
  183. cfg->n_spillover_bank_size = atoi(rvalue);
  184. }
  185. else if (strncmp(keyword, "n_one_cred_bank", FN_SZ-1) == 0 )
  186. {
  187. cfg->n_one_cred_bank = atoi(rvalue);
  188. }
  189. else if (strncmp(keyword, "n_two_cred_bank", FN_SZ-1) == 0 )
  190. {
  191. cfg->n_two_cred_bank = atoi(rvalue);
  192. }
  193. else if (strncmp(keyword, "n_spillover_bank", FN_SZ-1) == 0 )
  194. {
  195. cfg->n_spillover_bank = atoi(rvalue);
  196. }
  197. else if (strncmp(keyword, "n_one_cred_max_bank", FN_SZ-1) == 0 )
  198. {
  199. cfg->n_one_cred_max_bank = atoi(rvalue);
  200. }
  201. else if (strncmp(keyword, "n_two_cred_max_bank", FN_SZ-1) == 0 )
  202. {
  203. cfg->n_two_cred_max_bank = atoi(rvalue);
  204. }
  205. else if (strncmp(keyword, "n_spillover_max_bank", FN_SZ-1) == 0 )
  206. {
  207. cfg->n_spillover_max_bank = atoi(rvalue);
  208. }
  209. else if (strncmp(keyword, "one_cred_db_base", FN_SZ-1) == 0)
  210. {
  211. cfg->one_cred_db_base_fn = strdup(rvalue);
  212. }
  213. else if (strncmp(keyword, "two_cred_db_base", FN_SZ-1) == 0)
  214. {
  215. cfg->two_cred_db_base_fn = strdup(rvalue);
  216. }
  217. else if (strncmp(keyword, "spillover_db_base", FN_SZ-1) == 0)
  218. {
  219. cfg->spillover_db_base_fn = strdup(rvalue);
  220. }
  221. else if (strncmp(keyword, "db_suffix", FN_SZ-1) == 0)
  222. {
  223. cfg->db_fn_suffix = strdup(rvalue);
  224. }
  225. else if (strncmp(keyword, "ruleparam_db", FN_SZ-1) == 0)
  226. {
  227. cfg->ruleparam_db_fn = strdup(rvalue);
  228. }
  229. else if (strncmp(keyword, "high_watermark_threshold", FN_SZ-1) == 0)
  230. {
  231. cfg->high_watermark_threshold = atof(rvalue);
  232. }
  233. else if (strncmp(keyword, "low_watermark_threshold", FN_SZ-1) == 0)
  234. {
  235. cfg->low_watermark_threshold = atof(rvalue);
  236. }
  237. }
  238. fclose(fp);
  239. if (!cfg->ruleparam_db_fn)
  240. cfg->ruleparam_db_fn = strdup( RULEPARAM_DB_FILE );
  241. // If there were any errors, bail out
  242. //
  243. if ( (cfg->hash_modulus <= 0) ||
  244. (cfg->n_one_cred_max_bank <= 0) ||
  245. (cfg->n_two_cred_max_bank <= 0) ||
  246. (cfg->n_spillover_max_bank <= 0) ||
  247. (cfg->n_one_cred_bank_size <= 0) ||
  248. (cfg->n_two_cred_bank_size <= 0) ||
  249. (cfg->n_spillover_bank_size <= 0) ||
  250. (cfg->n_one_cred_bank <= 0) ||
  251. (cfg->n_two_cred_bank <= 0) ||
  252. (cfg->n_spillover_bank <= 0) ||
  253. (cfg->high_watermark_threshold <= 0.0) ||
  254. (cfg->high_watermark_threshold >= 1.0) ||
  255. (cfg->low_watermark_threshold <= 0.0) ||
  256. (cfg->low_watermark_threshold >= cfg->high_watermark_threshold) ||
  257. (!cfg->one_cred_db_base_fn) ||
  258. (!cfg->two_cred_db_base_fn) ||
  259. (!cfg->spillover_db_base_fn) ||
  260. (!cfg->db_fn_suffix) ||
  261. (!cfg->ruleparam_db_fn)
  262. )
  263. {
  264. if (cfg->one_cred_db_base_fn) free(cfg->one_cred_db_base_fn);
  265. if (cfg->two_cred_db_base_fn) free(cfg->two_cred_db_base_fn);
  266. if (cfg->spillover_db_base_fn) free(cfg->spillover_db_base_fn);
  267. if (cfg->db_fn_suffix) free(cfg->db_fn_suffix);
  268. if (cfg->ruleparam_db_fn) free(cfg->ruleparam_db_fn);
  269. return -1;
  270. }
  271. return 0;
  272. }
  273. // Dead simple config file parsing
  274. //
  275. int init_context_from_config( passdb_slim_context *ctx, char *config_fn )
  276. {
  277. int i, r;
  278. // Don't copy new values over until we're sure config file read
  279. // was successful. Store in local variables and copy over
  280. // afterwards.
  281. //
  282. passdb_slim_config cfg;
  283. r = read_config(&cfg, config_fn);
  284. if (r<0)
  285. return r;
  286. ctx->n_one_cred_bank = cfg.n_one_cred_bank;
  287. ctx->n_two_cred_bank = cfg.n_two_cred_bank;
  288. ctx->n_spillover_bank = cfg.n_spillover_bank;
  289. ctx->n_one_cred_max_bank = cfg.n_one_cred_max_bank;
  290. ctx->n_two_cred_max_bank = cfg.n_two_cred_max_bank;
  291. ctx->n_spillover_max_bank = cfg.n_spillover_max_bank;
  292. ctx->n_one_cred_bank_size = cfg.n_one_cred_bank_size;
  293. ctx->n_two_cred_bank_size = cfg.n_two_cred_bank_size;
  294. ctx->n_spillover_bank_size = cfg.n_spillover_bank_size;
  295. ctx->hash_modulus = cfg.hash_modulus;
  296. // Get rid of stale filenames
  297. //
  298. if (ctx->one_cred_db_bank_fn)
  299. {
  300. for (i=0; i<ctx->n_one_cred_max_bank; i++)
  301. if (ctx->one_cred_db_bank_fn[i])
  302. free(ctx->one_cred_db_bank_fn[i]);
  303. free(ctx->one_cred_db_bank_fn);
  304. }
  305. if (ctx->two_cred_db_bank_fn)
  306. {
  307. for (i=0; i<ctx->n_two_cred_max_bank; i++)
  308. if (ctx->two_cred_db_bank_fn[i])
  309. free(ctx->two_cred_db_bank_fn[i]);
  310. free(ctx->two_cred_db_bank_fn);
  311. }
  312. if (ctx->spillover_db_bank_fn)
  313. {
  314. for (i=0; i<ctx->n_spillover_max_bank; i++)
  315. if (ctx->spillover_db_bank_fn[i])
  316. free(ctx->spillover_db_bank_fn[i]);
  317. free(ctx->spillover_db_bank_fn);
  318. }
  319. if (ctx->one_cred_db_base_fn) free(ctx->one_cred_db_base_fn);
  320. if (ctx->two_cred_db_base_fn) free(ctx->two_cred_db_base_fn);
  321. if (ctx->spillover_db_base_fn) free(ctx->spillover_db_base_fn);
  322. if (ctx->db_fn_suffix) free(ctx->db_fn_suffix);
  323. if (ctx->ruleparam_db_fn) free(ctx->ruleparam_db_fn);
  324. if (ctx->logical_card_id_hash) free(ctx->logical_card_id_hash);
  325. if (ctx->rider_mag_hash) free(ctx->rider_mag_hash);
  326. if (ctx->rider_rf_hash) free(ctx->rider_rf_hash);
  327. ctx->one_cred_db_base_fn = cfg.one_cred_db_base_fn;
  328. ctx->two_cred_db_base_fn = cfg.two_cred_db_base_fn;
  329. ctx->spillover_db_base_fn = cfg.spillover_db_base_fn;
  330. ctx->db_fn_suffix = cfg.db_fn_suffix;
  331. ctx->ruleparam_db_fn = cfg.ruleparam_db_fn;
  332. ctx->high_watermark_threshold = cfg.high_watermark_threshold;
  333. ctx->low_watermark_threshold = cfg.low_watermark_threshold;
  334. //---------------------------------------
  335. // ONE CREDENTIAL bank
  336. // - filenames
  337. // - file descriptors
  338. // - bank (memory)
  339. //
  340. // allocate all filenames, even if we don't create the actual DB files
  341. //
  342. ctx->one_cred_db_bank_fn = (char **)malloc(sizeof(char *) * (ctx->n_one_cred_max_bank));
  343. CHECK_ALLOC_FAIL( (ctx->one_cred_db_bank_fn) );
  344. for (i=0; i<ctx->n_one_cred_max_bank; i++)
  345. {
  346. ctx->one_cred_db_bank_fn[i] = (char *)malloc(sizeof(char)*FN_SZ);
  347. CHECK_ALLOC_FAIL( (ctx->one_cred_db_bank_fn[i]) );
  348. snprintf(ctx->one_cred_db_bank_fn[i], FN_SZ, "%s%i%s", ctx->one_cred_db_base_fn, i, ctx->db_fn_suffix );
  349. }
  350. ctx->passes_one_cred_bank_fd = (int *)malloc(sizeof(int) * ctx->n_one_cred_max_bank );
  351. CHECK_ALLOC_FAIL( (ctx->passes_one_cred_bank_fd) );
  352. for (i=0; i<ctx->n_one_cred_max_bank; i++)
  353. ctx->passes_one_cred_bank_fd[i] = -1;
  354. ctx->rider_one_cred_bank = (void **)malloc(sizeof(void *) * ctx->n_one_cred_max_bank );
  355. CHECK_ALLOC_FAIL( (ctx->rider_one_cred_bank) );
  356. for (i=0; i<ctx->n_one_cred_max_bank; i++)
  357. ctx->rider_one_cred_bank[i] = NULL;
  358. //---------------------------------------
  359. // TWO CREDENTIAL bank
  360. // - filenames
  361. // - file descriptors
  362. // - bank (memory)
  363. //
  364. // allocate all filenames, even if we don't create the actual DB files
  365. //
  366. ctx->two_cred_db_bank_fn = (char **)malloc(sizeof(char *) * (ctx->n_two_cred_max_bank));
  367. CHECK_ALLOC_FAIL( (ctx->two_cred_db_bank_fn) );
  368. for (i=0; i<ctx->n_two_cred_max_bank; i++)
  369. {
  370. ctx->two_cred_db_bank_fn[i] = (char *)malloc(sizeof(char)*FN_SZ);
  371. CHECK_ALLOC_FAIL( (ctx->two_cred_db_bank_fn[i]) );
  372. snprintf(ctx->two_cred_db_bank_fn[i], FN_SZ, "%s%i%s", ctx->two_cred_db_base_fn, i, ctx->db_fn_suffix );
  373. }
  374. ctx->passes_two_cred_bank_fd = (int *)malloc(sizeof(int) * ctx->n_two_cred_max_bank );
  375. CHECK_ALLOC_FAIL( (ctx->passes_two_cred_bank_fd) );
  376. for (i=0; i<ctx->n_two_cred_max_bank; i++)
  377. ctx->passes_two_cred_bank_fd[i] = -1;
  378. ctx->rider_two_cred_bank = (void **)malloc(sizeof(void *) * ctx->n_two_cred_max_bank );
  379. CHECK_ALLOC_FAIL( (ctx->rider_two_cred_bank) );
  380. for (i=0; i<ctx->n_two_cred_max_bank; i++)
  381. ctx->rider_two_cred_bank[i] = NULL;
  382. //---------------------------------------
  383. // SPILLOVER
  384. // - filenames
  385. // - file descriptors
  386. // - bank (memory)
  387. //
  388. // allocate all filenames, even if we don't create the actual DB files
  389. //
  390. ctx->spillover_db_bank_fn = (char **)malloc(sizeof(char *) * (ctx->n_spillover_max_bank));
  391. CHECK_ALLOC_FAIL( (ctx->spillover_db_bank_fn) );
  392. for (i=0; i<ctx->n_spillover_max_bank; i++)
  393. {
  394. ctx->spillover_db_bank_fn[i] = (char *)malloc(sizeof(char)*FN_SZ);
  395. CHECK_ALLOC_FAIL( (ctx->spillover_db_bank_fn[i]) );
  396. snprintf(ctx->spillover_db_bank_fn[i], FN_SZ, "%s%i%s", ctx->spillover_db_base_fn, i, ctx->db_fn_suffix );
  397. }
  398. ctx->passes_spillover_bank_fd = (int *)malloc(sizeof(int) * ctx->n_spillover_max_bank );
  399. CHECK_ALLOC_FAIL( (ctx->passes_spillover_bank_fd) );
  400. for (i=0; i<ctx->n_spillover_max_bank; i++)
  401. ctx->passes_spillover_bank_fd[i] = -1;
  402. ctx->rider_spillover_bank = (void **)malloc(sizeof(void *) * ctx->n_spillover_max_bank );
  403. CHECK_ALLOC_FAIL( (ctx->rider_spillover_bank) );
  404. for (i=0; i<ctx->n_spillover_max_bank; i++)
  405. ctx->rider_spillover_bank[i] = NULL;
  406. ctx->logical_card_id_hash = (rider_node **)malloc(sizeof(rider_node *) * ctx->hash_modulus );
  407. CHECK_ALLOC_FAIL( (ctx->logical_card_id_hash) );
  408. ctx->rider_mag_hash = (rider_node **)malloc(sizeof(rider_node *) * ctx->hash_modulus );
  409. CHECK_ALLOC_FAIL( (ctx->rider_mag_hash) );
  410. ctx->rider_rf_hash = (rider_node **)malloc(sizeof(rider_node *) * ctx->hash_modulus );
  411. CHECK_ALLOC_FAIL( (ctx->rider_rf_hash) );
  412. for (i=0; i<ctx->hash_modulus; i++)
  413. {
  414. ctx->logical_card_id_hash[i] = NULL;
  415. ctx->rider_mag_hash[i] = NULL;
  416. ctx->rider_rf_hash[i] = NULL;
  417. }
  418. return 0;
  419. }