Commit ff257c1c authored by gates's avatar gates
Browse files

Augment the keydb config file format to allow processing keys to be placed in config file.

Update KEYDB.cfg example file accordingly.
parent 3c11317c
; DumpHD and libaacs key database file, format 1.4
; libaacs key database file, format 1.0
; ------------------------------------------------
;
; This config file formatted is an augmented form of DumpHD's config file
; format 1.4.
;
; This file is provided as documentation and example of the key database file
; used by DumpHD and libaacs, it contains no valid keys.
; used by libaacs, it contains no valid keys.
;
; The encoding of this file is UTF-8 without BOM (if the BOM is present the
; first line will not get recognized). Each line is treated as one key entry.
......@@ -14,6 +17,19 @@
; treated as comment.
;
;
; Processing Key entry block format
; ---------------------------------
; BEGIN PK_LIST
; <PROCESSING_KEY>
; ...
; END PK_LIST
;
; PROCESSING_KEY is any processing key, 32 characters long. Processing keys
; are placed between single lines starting with "BEGIN PK_LIST" and ending with
; "END PK_LIST". Only one processing key may appear in a single line. Each
; processing key line must end with at least one newline. A processing key
; block must contain at least one processing key.
;
; Key entry format
; ----------------
;
......@@ -91,6 +107,12 @@
; Examples
; --------
;
BEGIN PK_LIST
00000000000000000000000000000000 ; I am a comment
00000000000000000000000000000000
00000000000000000000000000000000
END PK_LIST
0000000000000000000000000000000000000000 = Movie Title | D | 0000-00-00 | V | 00000000000000000000000000000000 ; I am a comment
0000000000000000000000000000000000000000 = Movie Title ; I am NOT a comment | D | 1337-08-15 | T | 1-00000000000000000000000000000000 | 2-00000000000000000000000000000000 | 3-00000000000000000000000000000000
0000000000000000000000000000000000000000 = Movie Title | D | 2007-04-01 | V | 00000000000000000000000000000000 | T | 1-00000000000000000000000000000000
......
......@@ -109,13 +109,34 @@ static int print_config_entries(config_entry_list *list)
return 1;
}
/* Function to print config file */
static int print_config_file(config_file *cfgfile)
{
printf("Available processing keys:\n");
pk_list *cursor = cfgfile->pkl;
while (cursor)
{
if (!cursor->key)
break;
printf(" %s\n", cursor->key);
cursor = cursor->next;
}
printf("\n");
return print_config_entries(cfgfile->list);
}
/* main */
int main (int argc, char **argv)
{
config_entry_list *list = keydbcfg_new_config_entry_list();
int retval = keydbcfg_parse_config(list, argv[1]);
config_file *cfgfile = keydbcfg_new_config_file();
int retval = keydbcfg_parse_config(cfgfile, argv[1]);
if (!retval || !print_config_entries(list))
if (!retval || !print_config_file(cfgfile))
return EXIT_FAILURE;
return EXIT_SUCCESS;
......
......@@ -56,6 +56,10 @@ HEXSTRING ([0-9a-fA-F]{32,})
DISC_TITLE ([^\n|]*)
DIGIT ([0-9]+)
KEYWORD_BEGIN (BEGIN)
KEYWORD_END (END)
KEYWORD_PK_LIST (PK_LIST)
ENTRY_ID_DATE (\|[\t ]*[Dd][\t ]*\|)
ENTRY_ID_MEK (\|[\t ]*[Mm][\t ]*\|)
ENTRY_ID_VID (\|[\t ]*[Ii][\t ]*\|)
......@@ -96,6 +100,10 @@ BAD_ENTRY ([^\n])
return DIGIT;
}
{KEYWORD_BEGIN} { return KEYWORD_BEGIN; }
{KEYWORD_END} { return KEYWORD_END; }
{KEYWORD_PK_LIST} { return KEYWORD_PK_LIST; }
{ENTRY_ID_DATE} { return ENTRY_ID_DATE; }
{ENTRY_ID_MEK} { return ENTRY_ID_MEK; }
{ENTRY_ID_VID} { return ENTRY_ID_VID; }
......
......@@ -56,6 +56,10 @@ enum
ENTRY_TYPE_UK
};
static pk_list *new_pk_list();
static int add_pk_list(pk_list *list, const char *key);
static int add_pk_list_entry(config_file *cfgfile, const char *entry);
static config_entry_list *new_config_entry_list();
static int add_entry(config_entry_list *list, int type, const char *entry);
static digit_key_pair_list *new_digit_key_pair_list();
static int add_digit_key_pair(digit_key_pair_list *list, int type,
......@@ -64,7 +68,7 @@ static int add_digit_key_pair_entry(config_entry_list *list, int type,
unsigned int digit, const char *entry);
static int add_date_entry(config_entry_list *list, unsigned int year,
unsigned int month, unsigned int day);
void yyerror (void *scanner, config_entry_list *list, const char *msg);
void yyerror (void *scanner, config_file *cfgfile, const char *msg);
extern int yyget_lineno (void *scanner);
/* uncomment the line below for debugging */
......@@ -80,7 +84,7 @@ extern int yyget_lineno (void *scanner);
%yacc
%lex-param{void *scanner}
%parse-param{void *scanner}
%parse-param{config_entry_list *list}
%parse-param{config_file *cfgfile}
%union
{
......@@ -92,6 +96,10 @@ extern int yyget_lineno (void *scanner);
%token <string> DISC_TITLE
%token <digit> DIGIT
%token KEYWORD_BEGIN
%token KEYWORD_END
%token KEYWORD_PK_LIST
%token PUNCT_EQUALS_SIGN
%token PUNCT_VERTICAL_BAR
%token PUNCT_HYPHEN
......@@ -111,6 +119,40 @@ extern int yyget_lineno (void *scanner);
%type <string> discid disc_title
%%
config_file
: pk_block config_entries
;
pk_block
: pk_list_start pk_list pk_list_end
;
pk_list_start
: newline_list KEYWORD_BEGIN KEYWORD_PK_LIST NEWLINE
| KEYWORD_BEGIN KEYWORD_PK_LIST NEWLINE
;
pk_list_end
: newline_list KEYWORD_END KEYWORD_PK_LIST NEWLINE
| KEYWORD_END KEYWORD_PK_LIST NEWLINE
;
pk_list
: pk_list pk_entry NEWLINE
| pk_entry NEWLINE
;
pk_entry
: newline_list HEXSTRING
{
add_pk_list_entry(cfgfile, $2);
}
| HEXSTRING
{
add_pk_list_entry(cfgfile, $1);
}
;
config_entries
: config_entry_list newline_list
| config_entry_list
| config_entry_list error
......@@ -123,13 +165,17 @@ config_file
config_entry_list
: config_entry_list config_entry NEWLINE
{
list->next = keydbcfg_new_config_entry_list();
list = list->next;
config_entry_list *cursor = cfgfile->list;
while (cursor->next)
cursor = cursor->next;
cursor->next = new_config_entry_list();
}
| config_entry NEWLINE
{
list->next = keydbcfg_new_config_entry_list();
list = list->next;
config_entry_list *cursor = cfgfile->list;
while (cursor->next)
cursor = cursor->next;
cursor->next = new_config_entry_list();
}
| config_entry_list error NEWLINE
{
......@@ -156,8 +202,8 @@ newline_list
disc_info
: discid PUNCT_EQUALS_SIGN disc_title
{
add_entry(list, ENTRY_TYPE_DISCID, $1);
add_entry(list, ENTRY_TYPE_TITLE, $3);
add_entry(cfgfile->list, ENTRY_TYPE_DISCID, $1);
add_entry(cfgfile->list, ENTRY_TYPE_TITLE, $3);
}
;
......@@ -188,21 +234,21 @@ entry
date_entry
: ENTRY_ID_DATE DIGIT PUNCT_HYPHEN DIGIT PUNCT_HYPHEN DIGIT
{
add_date_entry(list, $2, $4, $6);
add_date_entry(cfgfile->list, $2, $4, $6);
}
;
mek_entry
: ENTRY_ID_MEK HEXSTRING
{
add_entry(list, ENTRY_TYPE_MEK, $2);
add_entry(cfgfile->list, ENTRY_TYPE_MEK, $2);
}
;
vid_entry
: ENTRY_ID_VID HEXSTRING
{
add_entry(list, ENTRY_TYPE_VID, $2);
add_entry(cfgfile->list, ENTRY_TYPE_VID, $2);
}
;
......@@ -218,14 +264,14 @@ bn_data_list
bn_data
: DIGIT PUNCT_HYPHEN HEXSTRING
{
add_digit_key_pair_entry(list, ENTRY_TYPE_BN, $1, $3);
add_digit_key_pair_entry(cfgfile->list, ENTRY_TYPE_BN, $1, $3);
}
;
vuk_entry
: ENTRY_ID_VUK HEXSTRING
{
add_entry(list, ENTRY_TYPE_VUK, $2);
add_entry(cfgfile->list, ENTRY_TYPE_VUK, $2);
}
;
......@@ -241,7 +287,7 @@ pak_data_list
pak_data
: DIGIT PUNCT_HYPHEN HEXSTRING
{
add_digit_key_pair_entry(list, ENTRY_TYPE_PAK, $1, $3);
add_digit_key_pair_entry(cfgfile->list, ENTRY_TYPE_PAK, $1, $3);
}
;
......@@ -257,7 +303,7 @@ tk_data_list
tk_data
: DIGIT PUNCT_HYPHEN HEXSTRING
{
add_digit_key_pair_entry(list, ENTRY_TYPE_TK, $1, $3);
add_digit_key_pair_entry(cfgfile->list, ENTRY_TYPE_TK, $1, $3);
}
;
......@@ -273,21 +319,24 @@ uk_data_list
uk_data
: DIGIT PUNCT_HYPHEN HEXSTRING
{
add_digit_key_pair_entry(list, ENTRY_TYPE_UK, $1, $3);
add_digit_key_pair_entry(cfgfile->list, ENTRY_TYPE_UK, $1, $3);
}
;
%%
/* Function to parse a config file */
int keydbcfg_parse_config(config_entry_list *list, const char *path)
int keydbcfg_parse_config(config_file *cfgfile, const char *path)
{
FILE * fp = fopen(path, "r");
if (!fp)
return 0;
cfgfile->pkl = new_pk_list();
cfgfile->list = new_config_entry_list();
void *scanner;
yylex_init(&scanner);
yyset_in(fp, scanner);
int retval = yyparse(scanner, list);
int retval = yyparse(scanner, cfgfile);
yylex_destroy(scanner);
if (retval)
......@@ -296,8 +345,60 @@ int keydbcfg_parse_config(config_entry_list *list, const char *path)
return 1;
}
/* Function that returns pointer to new config file object */
config_file *keydbcfg_new_config_file()
{
config_file *cfgfile = (config_file *)malloc(sizeof(*cfgfile));
cfgfile->pkl = NULL;
cfgfile->list = NULL;
return cfgfile;
}
/* Function to return new pk_list object */
static pk_list *new_pk_list()
{
pk_list *pkl = (pk_list *)malloc(sizeof(*pkl));
pkl->key = NULL;
pkl->next = NULL;
return pkl;
}
/* Function to add pk to config entry list */
static int add_pk_list(pk_list *list, const char *key)
{
if (!list)
{
printf("Error: No pk list passed as parameter.\n");
return 0;
}
pk_list *cursor = list;
while (cursor->next)
cursor = cursor->next;
cursor->key = (char*)malloc(strlen(key) + 1);
strcpy(cursor->key, key);
cursor->next = new_pk_list();
return 1;
}
static int add_pk_list_entry(config_file *cfgfile, const char *entry)
{
if (!cfgfile)
{
printf("Error: No config file object passed as parameter.\n");
return 0;
}
add_pk_list(cfgfile->pkl, entry);
return 1;
}
/* Function that returns pointer to new config entry list */
config_entry_list *keydbcfg_new_config_entry_list()
config_entry_list *new_config_entry_list()
{
config_entry_list *list = (config_entry_list *)malloc(sizeof(*list));
if (!list)
......@@ -490,7 +591,7 @@ static int add_date_entry(config_entry_list *list, unsigned int year,
}
/* Our definition of yyerror */
void yyerror (void *scanner, config_entry_list *list, const char *msg)
void yyerror (void *scanner, config_file *cfgfile, const char *msg)
{
fprintf(stderr, "%s: line %d\n", msg, yyget_lineno(scanner));
}
......@@ -52,6 +52,14 @@ typedef struct
unsigned int day;
} date_entry;
/* pk entry */
typedef struct pk_entry pk_list;
struct pk_entry
{
char *key;
pk_list *next;
};
/* main config entry struct */
typedef struct
{
......@@ -75,8 +83,16 @@ struct config_entry_list_t
config_entry_list *next;
};
/* struct representing the contents of a config file */
typedef struct config_file_t config_file;
struct config_file_t
{
pk_list *pkl;
config_entry_list *list;
};
/* Functions used throughout the parser */
int keydbcfg_parse_config(config_entry_list *list, const char *path);
config_entry_list *keydbcfg_new_config_entry_list();
int keydbcfg_parse_config(config_file *cfgfile, const char *path);
config_file *keydbcfg_new_config_file();
#endif
......@@ -370,8 +370,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 20
#define YY_END_OF_BUFFER 21
#define YY_NUM_RULES 23
#define YY_END_OF_BUFFER 24
/* This struct is not used in this scanner,
but its presence is necessary. */
struct yy_trans_info
......@@ -379,19 +379,22 @@ struct yy_trans_info
flex_int32_t yy_verify;
flex_int32_t yy_nxt;
};
static yyconst flex_int16_t yy_accept[184] =
static yyconst flex_int16_t yy_accept[214] =
{ 0,
0, 0, 2, 2, 21, 19, 1, 17, 17, 16,
5, 18, 14, 19, 15, 2, 1, 3, 2, 2,
2, 2, 2, 2, 17, 5, 0, 18, 0, 0,
0, 0, 0, 0, 0, 0, 0, 2, 3, 2,
2, 2, 5, 0, 0, 9, 0, 6, 0, 8,
0, 7, 0, 11, 0, 12, 0, 13, 0, 10,
0, 0, 2, 2, 24, 22, 1, 20, 20, 19,
5, 21, 17, 22, 22, 22, 22, 18, 2, 1,
3, 2, 2, 2, 2, 2, 2, 2, 2, 2,
20, 5, 0, 21, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 2, 3, 2, 2,
2, 2, 2, 2, 5, 0, 0, 7, 0, 0,
12, 0, 9, 0, 11, 0, 10, 0, 14, 0,
15, 0, 16, 0, 13, 2, 2, 2, 2, 2,
5, 0, 0, 0, 2, 2, 2, 2, 5, 0,
6, 0, 2, 2, 2, 2, 5, 0, 0, 2,
2, 2, 5, 0, 8, 2, 2, 2, 5, 0,
2, 2, 5, 0, 2, 2, 5, 0, 2, 2,
5, 0, 2, 2, 5, 0, 2, 2, 5, 0,
2, 2, 5, 0, 2, 2, 5, 0, 2, 2,
5, 0, 2, 2, 5, 0, 2, 2, 5, 0,
2, 2, 5, 0, 2, 2, 5, 0, 2, 2,
5, 0, 2, 2, 5, 0, 2, 2, 5, 0,
2, 2, 5, 0, 2, 2, 5, 0, 2, 2,
......@@ -399,6 +402,7 @@ static yyconst flex_int16_t yy_accept[184] =
2, 2, 5, 0, 2, 2, 5, 0, 2, 2,
5, 0, 2, 2, 5, 0, 2, 2, 5, 0,
2, 2, 5, 0, 2, 2, 5, 0, 2, 2,
5, 0, 2, 2, 4, 4, 2, 2, 4, 4,
2, 2, 0
} ;
......@@ -411,14 +415,14 @@ static yyconst flex_int32_t yy_ec[256] =
1, 2, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 5, 1, 1, 6, 6, 6,
6, 6, 6, 6, 6, 6, 6, 1, 7, 1,
8, 1, 1, 1, 9, 10, 9, 11, 9, 9,
1, 1, 12, 1, 1, 1, 13, 1, 1, 14,
1, 1, 1, 15, 16, 17, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 9, 10, 9, 11,
9, 9, 1, 1, 12, 1, 1, 1, 13, 1,
1, 14, 1, 1, 1, 15, 16, 17, 1, 1,
1, 1, 1, 18, 1, 1, 1, 1, 1, 1,
8, 1, 1, 1, 9, 10, 9, 11, 12, 9,
13, 1, 14, 1, 15, 16, 17, 18, 1, 19,
1, 1, 20, 21, 22, 23, 1, 1, 1, 1,
1, 1, 1, 1, 24, 1, 9, 25, 9, 26,
9, 9, 1, 1, 27, 1, 1, 1, 17, 1,
1, 28, 1, 1, 1, 29, 22, 23, 1, 1,
1, 1, 1, 30, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
......@@ -435,155 +439,268 @@ static yyconst flex_int32_t yy_ec[256] =
1, 1, 1, 1, 1
} ;
static yyconst flex_int32_t yy_meta[19] =
static yyconst flex_int32_t yy_meta[31] =
{ 0,
1, 1, 2, 1, 1, 3, 1, 1, 3, 3,
3, 1, 1, 1, 1, 1, 1, 4
3, 3, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 3, 3, 1, 1, 1, 4
} ;
static yyconst flex_int16_t yy_base[219] =
static yyconst flex_int16_t yy_base[249] =
{ 0,
0, 0, 18, 0, 318, 319, 319, 313, 313, 319,
309, 0, 319, 0, 35, 0, 0, 310, 310, 0,
47, 294, 0, 305, 319, 304, 0, 0, 0, 36,
37, 41, 42, 59, 60, 61, 62, 0, 319, 75,
303, 290, 301, 0, 64, 319, 65, 319, 69, 319,
70, 319, 71, 319, 72, 319, 73, 319, 74, 319,
87, 300, 299, 0, 93, 298, 297, 0, 99, 296,
295, 0, 105, 294, 293, 0, 111, 292, 291, 0,
117, 290, 289, 0, 123, 288, 287, 0, 129, 286,
285, 0, 135, 284, 283, 0, 141, 282, 281, 0,
147, 280, 279, 0, 153, 278, 275, 0, 159, 272,
268, 0, 165, 263, 262, 0, 171, 257, 256, 0,
177, 251, 250, 0, 183, 245, 244, 0, 189, 239,
238, 0, 195, 233, 232, 0, 201, 227, 226, 0,
207, 221, 220, 0, 213, 215, 214, 0, 219, 209,
208, 0, 225, 203, 202, 0, 231, 197, 196, 0,
237, 191, 190, 0, 243, 185, 184, 0, 249, 179,
178, 0, 255, 173, 172, 0, 261, 167, 166, 0,
0, 161, 319, 163, 272, 276, 279, 158, 157, 152,
151, 146, 145, 140, 139, 134, 133, 128, 127, 122,
121, 116, 115, 110, 109, 104, 103, 98, 97, 92,
91, 67, 66, 65, 62, 39, 38, 37
0, 0, 30, 0, 306, 786, 786, 301, 301, 786,
297, 0, 786, 0, 290, 283, 285, 59, 0, 0,
295, 291, 0, 83, 263, 0, 283, 56, 57, 273,
786, 281, 0, 0, 273, 274, 260, 0, 69, 70,
72, 75, 77, 81, 88, 89, 0, 786, 114, 277,
252, 90, 270, 256, 273, 0, 264, 786, 257, 99,
786, 102, 786, 104, 786, 108, 786, 111, 786, 112,
786, 113, 786, 114, 786, 139, 266, 254, 0, 251,
260, 0, 247, 250, 160, 257, 244, 247, 254, 0,
786, 239, 181, 252, 0, 237, 246, 0, 230, 202,
241, 225, 239, 0, 786, 223, 238, 0, 237, 0,
244, 236, 235, 0, 265, 234, 233, 0, 286, 232,
231, 0, 307, 230, 225, 0, 328, 224, 220, 0,
349, 219, 218, 0, 370, 217, 216, 0, 391, 215,
214, 0, 412, 213, 212, 0, 433, 211, 210, 0,
454, 209, 204, 0, 475, 203, 199, 0, 496, 198,
197, 0, 517, 196, 195, 0, 538, 194, 193, 0,
559, 192, 191, 0, 580, 190, 189, 0, 601, 188,
183, 0, 622, 182, 178, 0, 643, 177, 176, 0,
664, 175, 174, 0, 685, 173, 172, 0, 706, 171,
170, 0, 727, 169, 168, 0, 748, 167, 162, 0,
0, 161, 786, 160, 774, 778, 781, 159, 158, 157,
156, 155, 154, 153, 152, 151, 150, 149, 144, 143,
134, 133, 132, 130, 128, 127, 125, 124, 119, 118,
114, 109, 95, 94, 64, 63, 62, 61
} ;
static yyconst flex_int16_t yy_def[219] =
static yyconst flex_int16_t yy_def[249] =
{ 0,
183, 1, 183, 3, 183, 183, 183, 183, 183, 183,
184, 185, 183, 184, 183, 186, 186, 183, 186, 186,
186, 187, 186, 21, 183, 188, 188, 185, 15, 183,
183, 183, 183, 183, 183, 183, 183, 186, 183, 186,
40, 187, 189, 189, 183, 183, 183, 183, 183, 183,
183, 183, 183, 183, 183, 183, 183, 183, 183, 183,
40, 61, 190, 190, 61, 65, 191, 191, 65, 69,
192, 192, 69, 73, 193, 193, 73, 77, 194, 194,
77, 81, 195, 195, 81, 85, 196, 196, 85, 89,
197, 197, 89, 93, 198, 198, 93, 97, 199, 199,
97, 101, 200, 200, 101, 105, 201, 201, 105, 109,
202, 202, 109, 113, 203, 203, 113, 117, 204, 204,
117, 121, 205, 205, 121, 125, 206, 206, 125, 129,
207, 207, 129, 133, 208, 208, 133, 137, 209, 209,
137, 141, 210, 210, 141, 145, 211, 211, 145, 149,
212, 212, 149, 153, 213, 213, 153, 157, 214, 214,
157, 161, 215, 215, 161, 165, 216, 216, 165, 169,
217, 217, 169, 173, 218, 218, 173, 177, 218, 218,
177, 177, 0, 183, 183, 183, 183, 183, 183, 183,
183, 183, 183, 183, 183, 183, 183, 183, 183, 183,
183, 183, 183, 183, 183, 183, 183, 183, 183, 183,
183, 183, 183, 183, 183, 183, 183, 183
213, 1, 213, 3, 213, 213, 213, 213, 213, 213,
214, 215, 213, 214, 214, 214, 213, 213, 216, 216,
213, 216, 216, 216, 217, 216, 24, 24, 24, 216,
213, 218, 218, 215, 218, 213, 213, 18, 213, 213,
213, 213, 213, 213, 213, 213, 216, 213, 216, 49,
217, 49, 216, 216, 219, 219, 213, 213, 213, 213,
213, 213, 213, 213, 213, 213, 213, 213, 213, 213,
213, 213, 213, 213, 213, 216, 76, 216, 216, 216,
220, 220, 213, 213, 216, 85, 216, 216, 221, 221,
213, 213, 216, 93, 216, 216, 222, 222, 213, 216,
100, 216, 223, 223, 213, 216, 106, 216, 224, 224,
216, 111, 225, 225, 111, 115, 226, 226, 115, 119,
227, 227, 119, 123, 228, 228, 123, 127, 229, 229,
127, 131, 230, 230, 131, 135, 231, 231, 135, 139,
232, 232, 139, 143, 233, 233, 143, 147, 234, 234,
147, 151, 235, 235, 151, 155, 236, 236, 155, 159,
237, 237, 159, 163, 238, 238, 163, 167, 239, 239,
167, 171, 240, 240, 171, 175, 241, 241, 175, 179,