passdb_slim_config.c 17 KB

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