| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
#include "parse_util.h" |
| 22 |
#include "queue.h" |
| 23 |
|
| 24 |
|
| 25 |
extern FILE *yyin; |
| 26 |
extern void init_parser(int); |
| 27 |
extern int yyparse(void); |
| 28 |
extern void yyrestart(FILE *); |
| 29 |
extern queue_t id_queue; |
| 30 |
extern unsigned int policydb_errors; |
| 31 |
extern unsigned long policydb_lineno; |
| 32 |
extern policydb_t *policydbp; |
| 33 |
extern int mlspol; |
| 34 |
extern void set_source_file(const char *name); |
| 35 |
|
| 36 |
int read_source_policy(policydb_t * p, const char *file, const char *progname) |
| 37 |
{ |
| 38 |
yyin = fopen(file, "r"); |
| 39 |
if (!yyin) { |
| 40 |
fprintf(stderr, "%s: unable to open %s\n", progname, file); |
| 41 |
return -1; |
| 42 |
} |
| 43 |
set_source_file(file); |
| 44 |
|
| 45 |
if ((id_queue = queue_create()) == NULL) { |
| 46 |
fprintf(stderr, "%s: out of memory!\n", progname); |
| 47 |
return -1; |
| 48 |
} |
| 49 |
|
| 50 |
policydbp = p; |
| 51 |
mlspol = p->mls; |
| 52 |
|
| 53 |
init_parser(1); |
| 54 |
if (yyparse() || policydb_errors) { |
| 55 |
fprintf(stderr, |
| 56 |
"%s: error(s) encountered while parsing configuration\n", |
| 57 |
progname); |
| 58 |
return -1; |
| 59 |
} |
| 60 |
rewind(yyin); |
| 61 |
init_parser(2); |
| 62 |
set_source_file(file); |
| 63 |
yyrestart(yyin); |
| 64 |
if (yyparse() || policydb_errors) { |
| 65 |
fprintf(stderr, |
| 66 |
"%s: error(s) encountered while parsing configuration\n", |
| 67 |
progname); |
| 68 |
return -1; |
| 69 |
} |
| 70 |
queue_destroy(id_queue); |
| 71 |
|
| 72 |
if (policydb_errors) |
| 73 |
return -1; |
| 74 |
|
| 75 |
fclose(yyin); |
| 76 |
|
| 77 |
return 0; |
| 78 |
} |