noki0100

keydbcfg-parser.y

May 11th, 2014
313
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 18.51 KB | None | 0 0
  1. %code requires {
  2. #include "file/keydbcfg.h"
  3. }
  4.  
  5. %code {
  6. /*
  7. * This file is part of libaacs
  8. * Copyright (C) 2010 gates
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation; either
  13. * version 2.1 of the License, or (at your option) any later version.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library. If not, see
  22. * <http://www.gnu.org/licenses/>.
  23. */
  24.  
  25. #include "util/macro.h"
  26.  
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30.  
  31. /* Disable some warnings triggered by generated parser */
  32. #if defined __GNUC__
  33. #pragma GCC diagnostic ignored "-Wimplicit-function-declaration"
  34. #pragma GCC diagnostic ignored "-Wunused-parameter"
  35. #pragma GCC visibility push(hidden)
  36. #endif
  37.  
  38. /* Fix some warnings trigger by -Wundef which can't be ignored */
  39. #define YYENABLE_NLS 0
  40. #define YYLTYPE_IS_TRIVIAL 0
  41.  
  42. #define DIGIT_KEY_PAIR_LIST_FREE(X) do \
  43. { \
  44. while (X) \
  45. { \
  46. digit_key_pair_list *pnext = X->next;\
  47. X_FREE(X->key_pair.key); \
  48. X_FREE(X); \
  49. X = pnext; \
  50. } \
  51. } while (0);
  52.  
  53. /* enum used in certain functions to add proper title entry */
  54. enum
  55. {
  56. ENTRY_TYPE_DISCID,
  57. ENTRY_TYPE_TITLE,
  58. ENTRY_TYPE_DATE,
  59. ENTRY_TYPE_MEK,
  60. ENTRY_TYPE_VID,
  61. ENTRY_TYPE_BN,
  62. ENTRY_TYPE_VUK,
  63. ENTRY_TYPE_PAK,
  64. ENTRY_TYPE_TK,
  65. ENTRY_TYPE_UK
  66. };
  67.  
  68. static dk_list *new_dk_list(void);
  69. static pk_list *new_pk_list(void);
  70. static cert_list *new_cert_list(void);
  71.  
  72. static void add_dk_entry(config_file *cf, char *key, char *node, char *uv, char *u_mask_shift);
  73. static void add_pk_entry(config_file *cf, char *key);
  74. static void add_cert_entry(config_file *cf, char *host_priv_key, char *host_cert);
  75.  
  76. static title_entry_list *new_title_entry_list(void);
  77. static int add_entry(title_entry_list *list, int type, char *entry);
  78. static digit_key_pair_list *new_digit_key_pair_list(void);
  79. static digit_key_pair_list *add_digit_key_pair_entry(digit_key_pair_list *list,
  80. int type, unsigned int digit, char *key);
  81. static int add_date_entry(title_entry_list *list, unsigned int year,
  82. unsigned int month, unsigned int day);
  83. void yyerror (void *scanner, config_file *cf,
  84. title_entry_list *celist, digit_key_pair_list *dkplist,
  85. const char *msg);
  86. extern int libaacs_yyget_lineno (void *scanner);
  87.  
  88. /* uncomment the line below for debugging */
  89. // int yydebug = 1;
  90. }
  91. /* Options set to generate a reentrant parser that is POSIX yacc compatible
  92. * The basic 'scanner' parameters are set. Also, another parameter is set
  93. * to pass in a title entry list struct used to hold all title entries.
  94. * Most of these options are bison specific, but some BSD's have bison
  95. * compatibility support for these options in byacc.
  96. */
  97. %pure-parser
  98. %yacc
  99. %lex-param{void *scanner}
  100. %parse-param{void *scanner}
  101. %parse-param{config_file *cf}
  102. %parse-param{title_entry_list *celist}
  103. %parse-param{digit_key_pair_list *dkplist}
  104.  
  105. %union
  106. {
  107. char *string;
  108. unsigned int digit;
  109. }
  110.  
  111. %token <string> HEXSTRING
  112. %token <string> DISC_TITLE
  113. %token <digit> DIGIT
  114.  
  115. %token KEYWORD_DEVICE_KEY
  116. %token KEYWORD_DEVICE_NODE
  117. %token KEYWORD_KEY_UV
  118. %token KEYWORD_KEY_U_MASK_SHIFT
  119. %token KEYWORD_HOST_PRIV_KEY
  120. %token KEYWORD_HOST_CERT
  121. %token KEYWORD_HOST_NONCE
  122. %token KEYWORD_HOST_KEY_POINT
  123.  
  124. %token PUNCT_EQUALS_SIGN
  125. %token PUNCT_VERTICAL_BAR
  126. %token PUNCT_HYPHEN
  127.  
  128. %token ENTRY_ID_DK
  129. %token ENTRY_ID_PK
  130. %token ENTRY_ID_HC
  131. %token ENTRY_ID_DATE
  132. %token ENTRY_ID_MEK
  133. %token ENTRY_ID_VID
  134. %token ENTRY_ID_BN
  135. %token ENTRY_ID_VUK
  136. %token ENTRY_ID_PAK
  137. %token ENTRY_ID_TK
  138. %token ENTRY_ID_UK
  139.  
  140. %token NEWLINE
  141. %token BAD_ENTRY
  142.  
  143. %type <string> discid disc_title
  144. %type <string> host_priv_key host_cert host_nonce host_key_point hexstring_list
  145. %type <string> device_key device_node key_uv key_u_mask_shift
  146. %%
  147. config_file
  148. : config_entry_list newline_list
  149. | config_entry_list
  150. | newline_list
  151. | /* empty string */
  152. ;
  153.  
  154. config_entry_list
  155. : config_entry_list config_entry
  156. | config_entry
  157. ;
  158.  
  159. config_entry
  160. : dk_entry
  161. | pk_entry
  162. | host_cert_entry
  163. | title_entry
  164. | error NEWLINE
  165. {
  166. fprintf(stderr, "bad entry at or around line %d\n",
  167. libaacs_yyget_lineno(scanner) - 1);
  168. yyerrok;
  169. }
  170. ;
  171.  
  172. dk_entry
  173. : newline_list ENTRY_ID_DK device_key PUNCT_VERTICAL_BAR device_node PUNCT_VERTICAL_BAR key_uv PUNCT_VERTICAL_BAR key_u_mask_shift NEWLINE
  174. {
  175. add_dk_entry(cf, $3, $5, $7, $9);
  176. }
  177. | newline_list ENTRY_ID_DK device_key PUNCT_VERTICAL_BAR device_node NEWLINE
  178. {
  179. add_dk_entry(cf, $3, $5, NULL, NULL);
  180. }
  181. | ENTRY_ID_DK device_key PUNCT_VERTICAL_BAR device_node PUNCT_VERTICAL_BAR key_uv PUNCT_VERTICAL_BAR key_u_mask_shift NEWLINE
  182. {
  183. add_dk_entry(cf, $2, $4, $6, $8);
  184. }
  185. | ENTRY_ID_DK device_key PUNCT_VERTICAL_BAR device_node NEWLINE
  186. {
  187. add_dk_entry(cf, $2, $4, NULL, NULL);
  188. }
  189. ;
  190.  
  191. device_key
  192. : KEYWORD_DEVICE_KEY hexstring_list
  193. { $$ = $2; }
  194. ;
  195.  
  196. device_node
  197. : KEYWORD_DEVICE_NODE hexstring_list
  198. { $$ = $2; }
  199. ;
  200.  
  201. key_uv
  202. : KEYWORD_KEY_UV hexstring_list
  203. { $$ = $2; }
  204. ;
  205.  
  206. key_u_mask_shift
  207. : KEYWORD_KEY_U_MASK_SHIFT hexstring_list
  208. { $$ = $2; }
  209. ;
  210.  
  211. pk_entry
  212. : newline_list ENTRY_ID_PK hexstring_list NEWLINE
  213. {
  214. add_pk_entry(cf, $3);
  215. }
  216. | ENTRY_ID_PK hexstring_list NEWLINE
  217. {
  218. add_pk_entry(cf, $2);
  219. }
  220. ;
  221.  
  222. host_cert_entry
  223. : newline_list ENTRY_ID_HC host_priv_key PUNCT_VERTICAL_BAR host_cert PUNCT_VERTICAL_BAR host_nonce PUNCT_VERTICAL_BAR host_key_point NEWLINE
  224. {
  225. /* host_nonce and host_key_point are ignored, keep this for backward compatibility */
  226. X_FREE($7);
  227. X_FREE($9);
  228. add_cert_entry(cf, $3, $5);
  229. }
  230. | ENTRY_ID_HC host_priv_key PUNCT_VERTICAL_BAR host_cert PUNCT_VERTICAL_BAR host_nonce PUNCT_VERTICAL_BAR host_key_point NEWLINE
  231. {
  232. /* host_nonce and host_key_point are ignored, keep this for backward compatibility */
  233. X_FREE($6);
  234. X_FREE($8);
  235. add_cert_entry(cf, $2, $4);
  236. }
  237. | newline_list ENTRY_ID_HC host_priv_key PUNCT_VERTICAL_BAR host_cert NEWLINE
  238. {
  239. add_cert_entry(cf, $3, $5);
  240. }
  241. | ENTRY_ID_HC host_priv_key PUNCT_VERTICAL_BAR host_cert NEWLINE
  242. {
  243. add_cert_entry(cf, $2, $4);
  244. }
  245. ;
  246.  
  247. host_priv_key
  248. : KEYWORD_HOST_PRIV_KEY hexstring_list
  249. { $$ = $2; }
  250. ;
  251.  
  252. host_cert
  253. : KEYWORD_HOST_CERT hexstring_list
  254. { $$ = $2; }
  255. ;
  256.  
  257. host_nonce
  258. : KEYWORD_HOST_NONCE hexstring_list
  259. { $$ = $2; }
  260. ;
  261.  
  262. host_key_point
  263. : KEYWORD_HOST_KEY_POINT hexstring_list
  264. { $$ = $2; }
  265. ;
  266.  
  267. title_entry
  268. : newline_list disc_info entry_list NEWLINE
  269. | disc_info entry_list NEWLINE
  270. ;
  271.  
  272. newline_list
  273. : newline_list NEWLINE
  274. | NEWLINE
  275. ;
  276.  
  277. disc_info
  278. : discid PUNCT_EQUALS_SIGN disc_title
  279. {
  280. if (!cf->list) {
  281. celist = cf->list = new_title_entry_list();
  282. } else {
  283. celist->next = new_title_entry_list();
  284. celist = celist->next;
  285. }
  286. add_entry(celist, ENTRY_TYPE_DISCID, $1);
  287. add_entry(celist, ENTRY_TYPE_TITLE, $3);
  288. }
  289. ;
  290.  
  291. discid
  292. : hexstring_list
  293. ;
  294.  
  295. disc_title
  296. : DISC_TITLE
  297. ;
  298.  
  299. entry_list
  300. : entry_list entry
  301. | entry
  302. ;
  303.  
  304. entry
  305. : date_entry
  306. | mek_entry
  307. | vid_entry
  308. | bn_entry
  309. | vuk_entry
  310. | pak_entry
  311. | tk_entry
  312. | uk_entry
  313. ;
  314.  
  315. date_entry
  316. : ENTRY_ID_DATE DIGIT PUNCT_HYPHEN DIGIT PUNCT_HYPHEN DIGIT
  317. {
  318. add_date_entry(celist, $2, $4, $6);
  319. }
  320. ;
  321.  
  322. mek_entry
  323. : ENTRY_ID_MEK hexstring_list
  324. {
  325. add_entry(celist, ENTRY_TYPE_MEK, $2);
  326. }
  327. ;
  328.  
  329. vid_entry
  330. : ENTRY_ID_VID hexstring_list
  331. {
  332. add_entry(celist, ENTRY_TYPE_VID, $2);
  333. }
  334. ;
  335.  
  336. bn_entry
  337. : ENTRY_ID_BN bn_data_list
  338. {
  339. dkplist = NULL;
  340. }
  341. ;
  342.  
  343. bn_data_list
  344. : bn_data_list PUNCT_VERTICAL_BAR bn_data
  345. | bn_data
  346. ;
  347.  
  348. bn_data
  349. : DIGIT PUNCT_HYPHEN hexstring_list
  350. {
  351. if (!dkplist)
  352. {
  353. dkplist = new_digit_key_pair_list();
  354. celist->entry.bn = dkplist;
  355. }
  356. dkplist = add_digit_key_pair_entry(dkplist, ENTRY_TYPE_BN, $1, $3);
  357. }
  358. ;
  359.  
  360. vuk_entry
  361. : ENTRY_ID_VUK hexstring_list
  362. {
  363. add_entry(celist, ENTRY_TYPE_VUK, $2);
  364. }
  365. ;
  366.  
  367. pak_entry
  368. : ENTRY_ID_PAK pak_data_list
  369. {
  370. dkplist = NULL;
  371. }
  372. ;
  373.  
  374. pak_data_list
  375. : pak_data_list PUNCT_VERTICAL_BAR pak_data
  376. | pak_data
  377. ;
  378.  
  379. pak_data
  380. : DIGIT PUNCT_HYPHEN hexstring_list
  381. {
  382. if (!dkplist)
  383. {
  384. dkplist = new_digit_key_pair_list();
  385. celist->entry.pak = dkplist;
  386. }
  387. dkplist = add_digit_key_pair_entry(dkplist, ENTRY_TYPE_PAK, $1, $3);
  388. }
  389. ;
  390.  
  391. tk_entry
  392. : ENTRY_ID_TK tk_data_list
  393. {
  394. dkplist = NULL;
  395. }
  396. ;
  397.  
  398. tk_data_list
  399. : tk_data_list PUNCT_VERTICAL_BAR tk_data
  400. | tk_data
  401. ;
  402.  
  403. tk_data
  404. : DIGIT PUNCT_HYPHEN hexstring_list
  405. {
  406. if (!dkplist)
  407. {
  408. dkplist = new_digit_key_pair_list();
  409. celist->entry.tk = dkplist;
  410. }
  411. dkplist = add_digit_key_pair_entry(dkplist, ENTRY_TYPE_TK, $1, $3);
  412. }
  413. ;
  414.  
  415. uk_entry
  416. : ENTRY_ID_UK uk_data_list
  417. {
  418. dkplist = NULL;
  419. }
  420. ;
  421.  
  422. uk_data_list
  423. : uk_data_list PUNCT_VERTICAL_BAR uk_data
  424. | uk_data
  425. ;
  426.  
  427. uk_data
  428. : DIGIT PUNCT_HYPHEN hexstring_list
  429. {
  430. if (!dkplist)
  431. {
  432. dkplist = new_digit_key_pair_list();
  433. celist->entry.uk = dkplist;
  434. }
  435. dkplist = add_digit_key_pair_entry(dkplist, ENTRY_TYPE_UK, $1, $3);
  436. }
  437. ;
  438.  
  439. hexstring_list
  440. : hexstring_list HEXSTRING
  441. {
  442. char *str = (char*)malloc(strlen($1) + strlen($2) + 1);
  443. strcpy(str, $1);
  444. strcat(str, $2);
  445. $$ = str;
  446. X_FREE($1);
  447. }
  448. | HEXSTRING
  449. {
  450. char *str = (char*)malloc(strlen($1) + 1);
  451. strcpy(str, $1);
  452. $$ = str;
  453. }
  454. ;
  455. %%
  456. /* Function to parse a config file */
  457. int keydbcfg_parse_config(config_file *cfgfile, const char *path)
  458. {
  459. if (!cfgfile || !path)
  460. return 0;
  461.  
  462. FILE * fp = fopen(path, "r");
  463. if (!fp)
  464. return 0;
  465.  
  466. void *scanner;
  467. libaacs_yylex_init(&scanner);
  468. libaacs_yyset_in(fp, scanner);
  469. int retval = yyparse(scanner, cfgfile, NULL, NULL);
  470. libaacs_yylex_destroy(scanner);
  471.  
  472. fclose(fp);
  473.  
  474. if (retval)
  475. return 0;
  476.  
  477. return 1;
  478. }
  479.  
  480. /* Function that returns pointer to new config file object */
  481. config_file *keydbcfg_new_config_file(void)
  482. {
  483. config_file *cfgfile = (config_file *)malloc(sizeof(*cfgfile));
  484. memset(cfgfile, 0, sizeof(*cfgfile));
  485. return cfgfile;
  486. }
  487.  
  488. /* Function that closes and frees a config file object */
  489. int keydbcfg_config_file_close(config_file *cfgfile)
  490. {
  491. if (!cfgfile) {
  492. return 0;
  493. }
  494.  
  495. /* free pk list */
  496. while (cfgfile->pkl)
  497. {
  498. pk_list *next = cfgfile->pkl->next;
  499. X_FREE(cfgfile->pkl);
  500. cfgfile->pkl = next;
  501. }
  502.  
  503. /* free dk list */
  504. while (cfgfile->dkl)
  505. {
  506. dk_list *next = cfgfile->dkl->next;
  507. X_FREE(cfgfile->dkl);
  508. cfgfile->dkl = next;
  509. }
  510.  
  511. /* free host cert list */
  512. while (cfgfile->host_cert_list)
  513. {
  514. cert_list *next = cfgfile->host_cert_list->next;
  515. X_FREE(cfgfile->host_cert_list);
  516. cfgfile->host_cert_list = next;
  517. }
  518.  
  519. /* free title entries */
  520. while (cfgfile->list)
  521. {
  522. title_entry_list *next = cfgfile->list->next;
  523. X_FREE(cfgfile->list->entry.title);
  524. X_FREE(cfgfile->list->entry.mek);
  525. X_FREE(cfgfile->list->entry.vid);
  526. DIGIT_KEY_PAIR_LIST_FREE(cfgfile->list->entry.bn);
  527. X_FREE(cfgfile->list->entry.vuk);
  528. DIGIT_KEY_PAIR_LIST_FREE(cfgfile->list->entry.pak);
  529. DIGIT_KEY_PAIR_LIST_FREE(cfgfile->list->entry.tk);
  530. DIGIT_KEY_PAIR_LIST_FREE(cfgfile->list->entry.uk);
  531. X_FREE(cfgfile->list);
  532. cfgfile->list = next;
  533. }
  534.  
  535. /* free the config file object */
  536. X_FREE(cfgfile);
  537.  
  538. return 1;
  539. }
  540.  
  541. /* Function to return new dk_list object */
  542. static dk_list *new_dk_list(void)
  543. {
  544. dk_list *dkl = (dk_list *)malloc(sizeof(*dkl));
  545. memset(dkl, 0, sizeof(*dkl));
  546. return dkl;
  547. }
  548.  
  549. /* Function to add dk to config file */
  550. static void add_dk_entry(config_file *cf, char *key, char *node, char *uv, char *u_mask_shift)
  551. {
  552. if (strlen(key) != 32) {
  553. fprintf(stderr, "ignoring bad DK entry %s\n", key);
  554. X_FREE(key);
  555. return;
  556. }
  557.  
  558. dk_list *entry = cf->dkl;
  559. if (!entry) {
  560. entry = cf->dkl = new_dk_list();
  561. } else {
  562. for (; entry->next; entry = entry->next);
  563. entry->next = new_dk_list();
  564. entry = entry->next;
  565. }
  566.  
  567. hexstring_to_hex_array(entry->key, 16, key);
  568. X_FREE(key);
  569. entry->node = strtoul(node, NULL, 16);
  570. X_FREE(node);
  571.  
  572. if (uv) {
  573. entry->uv = strtoul(uv, NULL, 16);
  574. X_FREE(uv);
  575. }
  576. if (u_mask_shift) {
  577. entry->u_mask_shift = strtoul(u_mask_shift, NULL, 16);
  578. X_FREE(u_mask_shift);
  579. }
  580. }
  581.  
  582. /* Function to return new pk_list object */
  583. static pk_list *new_pk_list(void)
  584. {
  585. pk_list *pkl = (pk_list *)malloc(sizeof(*pkl));
  586. memset(pkl, 0, sizeof(*pkl));
  587. return pkl;
  588. }
  589.  
  590. /* Function to add pk to config file */
  591. static void add_pk_entry(config_file *cf, char *key)
  592. {
  593. if (strlen(key) != 32) {
  594. fprintf(stderr, "ignoring bad PK entry %s\n", key);
  595. X_FREE(key);
  596. return;
  597. }
  598.  
  599. pk_list *entry = cf->pkl;
  600. if (!entry) {
  601. entry = cf->pkl = new_pk_list();
  602. } else {
  603. for (; entry->next; entry = entry->next);
  604. entry->next = new_pk_list();
  605. entry = entry->next;
  606. }
  607.  
  608. hexstring_to_hex_array(entry->key, 16, key);
  609. X_FREE(key);
  610. }
  611.  
  612. /* Function to create new certificate list */
  613. static cert_list *new_cert_list(void)
  614. {
  615. cert_list *list = (cert_list *)malloc(sizeof(*list));
  616. if (!list)
  617. {
  618. printf("Error allocating memory for new certificate list!\n");
  619. return NULL;
  620. }
  621.  
  622. memset(list, 0, sizeof(*list));
  623.  
  624. return list;
  625. }
  626.  
  627. /* Function to add certificate list entry into config file object */
  628. static void add_cert_entry(config_file *cf, char *host_priv_key, char *host_cert)
  629. {
  630. if (strlen(host_priv_key) != 40) {
  631. fprintf(stderr, "ignoring bad private key entry %s\n", host_priv_key);
  632. X_FREE(host_priv_key);
  633. X_FREE(host_cert);
  634. return;
  635. }
  636. if (strlen(host_cert) != 184) {
  637. fprintf(stderr, "ignoring bad certificate entry %s\n", host_cert);
  638. X_FREE(host_priv_key);
  639. X_FREE(host_cert);
  640. return;
  641. }
  642.  
  643. cert_list *entry = cf->host_cert_list;
  644. if (!entry) {
  645. entry = cf->host_cert_list = new_cert_list();
  646. } else {
  647. for (; entry->next; entry = entry->next);
  648. entry->next = new_cert_list();
  649. entry = entry->next;
  650. }
  651.  
  652. hexstring_to_hex_array(entry->host_priv_key, 20, host_priv_key);
  653. X_FREE(host_priv_key);
  654. hexstring_to_hex_array(entry->host_cert, 92, host_cert);
  655. X_FREE(host_cert);
  656. }
  657.  
  658. /* Function that returns pointer to new title entry list */
  659. title_entry_list *new_title_entry_list(void)
  660. {
  661. title_entry_list *list = (title_entry_list *)malloc(sizeof(*list));
  662. if (!list)
  663. {
  664. printf("Error allocating memory for new title entry list!\n");
  665. return NULL;
  666. }
  667.  
  668. memset(list, 0, sizeof(*list));
  669.  
  670. return list;
  671. }
  672.  
  673. #define CHECK_KEY_LENGTH(name, len) \
  674. if (strlen(entry) != len) { \
  675. fprintf(stderr, "Ignoring bad "name" entry %s\n", entry); \
  676. X_FREE(entry); \
  677. break; \
  678. }
  679.  
  680. /* Function to add standard string entries to a config entry */
  681. static int add_entry(title_entry_list *list, int type, char *entry)
  682. {
  683. if (!list)
  684. {
  685. printf("Error: No title list passed as parameter.\n");
  686. return 0;
  687. }
  688.  
  689. switch (type)
  690. {
  691. case ENTRY_TYPE_DISCID:
  692. CHECK_KEY_LENGTH("discid", 40)
  693. hexstring_to_hex_array(list->entry.discid, 20, entry);
  694. X_FREE(entry);
  695. break;
  696.  
  697. case ENTRY_TYPE_TITLE:
  698. X_FREE(list->entry.title);
  699. list->entry.title = (char*)malloc(strlen(entry) + 1);
  700. strcpy(list->entry.title, entry);
  701. break;
  702.  
  703. case ENTRY_TYPE_MEK:
  704. CHECK_KEY_LENGTH("mek", 32)
  705. X_FREE(list->entry.mek);
  706. list->entry.mek = entry;
  707. break;
  708.  
  709. case ENTRY_TYPE_VID:
  710. CHECK_KEY_LENGTH("vid", 32)
  711. X_FREE(list->entry.vid);
  712. list->entry.vid = entry;
  713. break;
  714.  
  715. case ENTRY_TYPE_VUK:
  716. CHECK_KEY_LENGTH("vuk", 32)
  717. X_FREE(list->entry.vuk);
  718. list->entry.vuk = entry;
  719. break;
  720.  
  721. default:
  722. X_FREE(entry);
  723. printf("WARNING: entry type passed in unknown\n");
  724. return 0;
  725. }
  726.  
  727. return 1;
  728. }
  729.  
  730. /* Function that returns pointer to new digit key pair list */
  731. static digit_key_pair_list *new_digit_key_pair_list(void)
  732. {
  733. digit_key_pair_list *list = (digit_key_pair_list *)malloc(sizeof(*list));
  734. if (!list)
  735. {
  736. printf("Error allocating memory for new digit key pair entry list!\n");
  737. return NULL;
  738. }
  739.  
  740. memset(list, 0, sizeof(*list));
  741.  
  742. return list;
  743. }
  744.  
  745. /* Function used to add a digit/key pair to a list of digit key pair entries */
  746. static digit_key_pair_list *add_digit_key_pair_entry(digit_key_pair_list *list,
  747. int type, unsigned int digit, char *key)
  748. {
  749. if (!list)
  750. {
  751. printf("Error: No digit key pair list passed as parameter.\n");
  752. return NULL;
  753. }
  754.  
  755. list->key_pair.digit = digit;
  756. list->key_pair.key = key;
  757.  
  758. list->next = new_digit_key_pair_list();
  759.  
  760. return list->next;
  761. }
  762.  
  763. /* Function to add a date entry */
  764. static int add_date_entry(title_entry_list *list, unsigned int year,
  765. unsigned int month, unsigned int day)
  766. {
  767. if (!list)
  768. {
  769. printf("Error: No title list passed as parameter.\n");
  770. return 0;
  771. }
  772.  
  773. list->entry.date.year = year;
  774. list->entry.date.month = month;
  775. list->entry.date.day = day;
  776.  
  777. return 1;
  778. }
  779.  
  780. /* Our definition of yyerror */
  781. void yyerror (void *scanner, config_file *cf,
  782. title_entry_list *celist, digit_key_pair_list *dkplist,
  783. const char *msg)
  784. {
  785. fprintf(stderr, "%s: line %d\n", msg, libaacs_yyget_lineno(scanner));
  786. }
Advertisement
Add Comment
Please, Sign In to add comment